$ >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. 【Foreign】减法 [二分][贪心]

    减法 Time Limit: 10 Sec  Memory Limit: 256 MB Description 给你一个n个数的序列A,并且给出m次操作B. 操作的含义是:每次从A中选出不同的B_i个 ...

  2. 【POJ】3070 Fibonacci

    [算法]矩阵快速幂 [题解] 根据f[n]=f[n-1]+f[n-2],可以构造递推矩阵: $$\begin{vmatrix}1 & 1\\ 1 & 0\end{vmatrix} \t ...

  3. js面向对象的几种常见写法

    下面是一个简单的js对象:定义Circle类,拥有成员变量r,常量PI和计算面积的成员函数area(),常用为第一种和第三种. 1.工厂方式 var Circle = function() { var ...

  4. 【洛谷 P4166】 [SCOI2007]最大土地面积(凸包,旋转卡壳)

    题目链接 又调了我两个多小时巨亏 直接\(O(n^4)\)枚举4个点显然不行. 数据范围提示我们需要一个\(O(n^2)\)的算法. 于是\(O(n^2)\)枚举对角线,然后在这两个点两边各找一个点使 ...

  5. 【leetcode 简单】第四十九题 颠倒二进制位

    颠倒给定的 32 位无符号整数的二进制位. 示例: 输入: 43261596 输出: 964176192 解释: 43261596 的二进制表示形式为 000000101001010000011110 ...

  6. 一款基于react-native的弹窗提示组件

    介绍一款基于react-native的弹窗提示插件 react-native-ms , github地址:https://github.com/jiangzhenfei/react-native-ms ...

  7. CentOS 6.5 安装 MongoDB

    1. 配置 yum 新建 /etc/yum.repos.d/mongodb-org-3.4.repo 文件,使用以下配置:(适用于 MongoDB 3.0 以后版本) [mongodb-org-3.4 ...

  8. Neuroph studio 入门教程

    PERCEPTRON Perceptron is a simple two layer neural network with several neurons in input layer, and ...

  9. 一个Servlet处理增删改查的方法

    处理的思路是在servlet中定义不同的增删改查方法,页面请求 的时候携带请求的参数,根据参数判断调用不同的方法. package cn.xm.small.Servlet; import java.i ...

  10. Deep Learning基础--机器翻译BLEU与Perplexity详解

    前言 近年来,在自然语言研究领域中,评测问题越来越受到广泛的重视,可以说,评测是整个自然语言领域最核心和关键的部分.而机器翻译评价对于机器翻译的研究和发展具有重要意义:机器翻译系统的开发者可以通过评测 ...