$ >AtcoderGrandContest \space 005 F. \ Many\ Easy\ Problems<$

题目大意 :

有一棵大小为 \(n\) 的树,对于每一个 \(k \in[1,n]\) ,求出在所有在树中选 \(k\) 个点的方案对应的包含这 \(k\) 个点的最小联通块大小之和

\(1 \leq n \leq 2 \times 10^5\)

解题思路 :

容易发现,对于一组选取方案,包含它的最小联通块是唯一的,不妨考虑每一个点对这个联通块的贡献.

观察发现,一个点如果在一个最小联通块中,当且仅当有两个选取点的简单路径经过它

那么点 \(u\) 对 \(k\) 个点的贡献就是 \(C_n^k -\sum_{v} C_{sz[v]}^k-C_{n-sz[u]}^k\)

观察发现这个式子只和 \(sz\) 有关,不妨设 \(tot[i]\) 表示 \(sz[u]=i\) 的点的数量

考虑除根以外的每一个点只会在其父亲计算的时候被减去一个 \(C_{sz[u]}^k\) ,同时每一种 \(sz[u]\) 都会在计算大小为 \(n-sz[u]\) 的子树的时候被减去一次

所以 \(C_{sz[u]}^k\) 的被计算次数是 \(tot[sz[u]] + tot[n-sz[u]]\)

那么最终答案的式子就是 \(Ans_j =n \times C_n^j -\sum_{i=1}^n (tot[i]+tot[n-i])\times C_i^j\)

设 \(inv[i]\) 表示 \(i!\) 关于 \(Mod\) 的逆元,将后面的组合数拆开来可以得到

\(Ans_j =n \times C_n^j -\sum_{i=1}^n (tot[i]+tot[n-i])\times i! \times inv[j] \times inv[i-j]\)

设 \(A[i] = (tot[i]+tot[n-i])\times i!\) ,则 \(Ans_j = n \times C_n^j \times inv[j] - \sum_{i=1}^nA[i]\times inv[i-j]\), 后者 \(NTT\) 进行计算即可

/*program by mangoyang*/
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#include<bits/stdc++.h>
#define inf (0x7f7f7f7f)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;
using namespace std;
template <class T>
inline void read(T &x){
int f = 0, ch = 0; x = 0;
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = 1;
for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
if(f) x = -x;
} #define int ll const int N = 1605005, L = 200005, P = 924844033, G = 5;
vector<int> g[N];
int inv[N], iv[N], s[N], f[N], tot[N], sz[N], js[N], n;
inline int Pow(int a, int b){
int ans = 1;
for(; b; b >>= 1, a = a * a % P)
if(b & 1) ans = ans * a % P;
return ans;
}
namespace NTT{
int rev[N];
inline int Getrev(int ned){
int lg = 0, len = 1;
for(; len <= ned; len <<= 1, lg++);
for(int i = 0; i < len; i++)
rev[i] = (rev[i>>1] >> 1) | ((i & 1) << (lg - 1));
return len;
}
inline void DFT(int *A, int len, int type){
for(int i = 0; i < len; i++) if(i < rev[i]) swap(A[i], A[rev[i]]);
for(int k = 2; k <= len; k <<= 1){
int w = Pow(G, (P - 1) / k); if(type == -1) w = Pow(w, P - 2);
for(int i = 0; i < len; i += k){
int now = 1;
for(int j = i; j < i + (k >> 1); j++, (now *= w) %= P){
int x = A[j], y = (now * A[j+(k>>1)]) % P;
A[j] = (x + y) % P, A[j+(k>>1)] = (x - y + P) % P;
}
}
}
if(type == -1){
int now = Pow(len, P - 2);
for(int i = 0; i < len; i++) (A[i] *= now) %= P;
}
}
inline void Times(int *A, int *B, int lena, int lenb){
int len = Getrev(lena + lenb + 1);
DFT(A, len, 1), DFT(B, len, 1);
for(int i = 0; i < len; i++) A[i] = A[i] * B[i] % P;
DFT(A, len, -1);
}
}
inline void dfs(int u, int fa){
sz[u] = 1, f[u] = fa;
for(int i = 0; i < g[u].size(); i++)
if(g[u][i] != fa) dfs(g[u][i], u), sz[u] += sz[g[u][i]];
}
inline int C(int x, int y){
return js[x] * inv[y] % P * inv[x-y] % P;
}
signed main(){
read(n), js[0] = 1, inv[0] = iv[L] = 1;
for(int i = 1; i <= n; i++){
js[i] = js[i-1] * i % P;
iv[L-i] = inv[i] = Pow(js[i], P - 2);
}
for(int i = 1, x, y; i < n; i++){
read(x), read(y);
g[x].push_back(y), g[y].push_back(x);
}
dfs(1, 0);
for(int i = 2; i <= n; i++) tot[sz[i]]++;
for(int i = 1; i <= n; i++)
s[L+i] = (tot[i] + tot[n-i]) * js[i] % P;
NTT::Times(s, iv, L + n + 1, L + n + 1);
for(int i = 1; i <= n; i++){
int A = n * C(n, i) % P;
int B = inv[i] * s[2*L+i] % P;
printf("%lld\n", ((A - B) % P + P) % P);
}
return 0;
}

AtcoderGrandContest 005 F. Many Easy Problems的更多相关文章

  1. [题解] Atcoder AGC 005 F Many Easy Problems NTT,组合数学

    题目 观察当k固定时答案是什么.先假设每个节点对答案的贡献都是\(\binom{n}{k}\),然后再减掉某个点没有贡献的选点方案数.对于一个节点i,它没有贡献的方案数显然就是所有k个节点都选在i连出 ...

  2. 【AtCoder】AGC005 F - Many Easy Problems 排列组合+NTT

    [题目]F - Many Easy Problems [题意]给定n个点的树,定义S为大小为k的点集,则f(S)为最小的包含点集S的连通块大小,求k=1~n时的所有点集f(S)的和取模92484403 ...

  3. 解题:AT2064 Many Easy Problems&EXNR #1 T3 两开花

    题面 两道题比较像,放在一起写了,后者可以看成前者的加强版 (sto ztb orz) 先看AT那道题 考虑计算每个点的贡献,用容斥计算:每个点没有贡献当且仅当选的所有点都在以他为根时的一个子节点的子 ...

  4. Codeforces 913D - Too Easy Problems

    913D - Too Easy Problems 思路:二分check k 代码: #include<bits/stdc++.h> using namespace std; #define ...

  5. 【CodeForces】913 D. Too Easy Problems

    [题目]D. Too Easy Problems [题意]给定n个问题和总时限T,每个问题给定时间ti和限制ai,当解决的问题数k<=ai时问题有效,求在时限T内选择一些问题解决的最大有效问题数 ...

  6. 【AGC005 F】Many Easy Problems

    神他吗一天考一道码农题两道 FFT(其实还是我推式子一窍不通) 题意 给你一棵 \(n\) 个点的树,再给你一个常数 \(k\). 设 \(S\) 为树上某些点的集合,定义 \(f(S)\) 为最小的 ...

  7. 【AGC 005F】Many Easy Problems

    Description One day, Takahashi was given the following problem from Aoki: You are given a tree with ...

  8. AtCoder - 2064 Many Easy Problems

    Problem Statement One day, Takahashi was given the following problem from Aoki: You are given a tree ...

  9. Codeforces B. Too Easy Problems

    题目描述: time limit per test 2 seconds memory limit per test 256 megabytes input standard input output ...

随机推荐

  1. javascript中各类的prototype属性

    prototype 作用:获取调用对象的对象原型引用 应用:可以为某对象原型添加方法 例: function getMax() { var max = this[0]; for(var x=0; x& ...

  2. 【Atcoder】AGC 020 B - Ice Rink Game 递推

    [题意]n个人进行游戏,每轮只保留最大的a[i]倍数的人,最后一轮过后剩余2人,求最小和最大的n,或-1.n<=10^5. [算法]递推||二分 [题解]令L(i),R(i)表示第i轮过后的最小 ...

  3. Vue笔记之模板语法

    插值 比较常用的就是插值,插值就是{{ foobar }}用两个大括号包起来的一个变量,显示的时候会将双大括号标签替换为这个变量的值. 基本的用法就是: <p>{{ message }}& ...

  4. 64_t4

    texlive-hardwrap-svn21396.0.2-33.fc26.2.noarch.rpm 24-May-2017 15:41 35930 texlive-harmony-doc-svn15 ...

  5. easyui datagrid 去掉 全选checkbox

    在加载 表格的时候添加事件:onLoadSuccess 在事件中写入下面句,用空代替原有HTML 达到取消效果. $(".datagrid-header-check").html( ...

  6. js弱数据类型的坑

    1.从表单获取的value是字符串,如果需要为数字相加,则需要转换为number类型 <input type="number" id="val1"> ...

  7. Geoserver WFS跨域设置

    测试版本为geoserver2.11.0. 两种方法都可以实现跨域设置: 第一种: 下载跨域jar包jetty-servlets.jar(下载geoserver使用的对应jetty版本——可以查看&l ...

  8. 连接数据库:ERROR:The server time zone value '?й???????' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration prop

    本打算在maven项目中配置mybatis试试看,想到mybatis如果不是在容器中运行,那么他的事务控制实际上可以使用的是jdbc的提交和回滚,这就要在pom.xml文件中配置mysql-conne ...

  9. Codeforces 86D - Powerful array(莫队算法)

    题目链接:http://codeforces.com/problemset/problem/86/D 题目大意:给定一个数组,每次询问一个区间[l,r],设cnt[i]为数字i在该区间内的出现次数,求 ...

  10. Python股票信息抓取(三)

    最近在看mongodb,然后会用了一些最简单的mongodb的操作,然后想着结合股票信息的数据的抓取,然后将数据存储在mongodb中,对于mongo和数据库的最大的区别是,mongo不需要建表,直接 ...