Description

One day, Takahashi was given the following problem from Aoki:

You are given a tree with N vertices and an integer K. The vertices are numbered 1 through N. The edges are represented by pairs of integers (ai,bi).

For a set S of vertices in the tree, let f(S) be the minimum number of the vertices in a subtree of the given tree that contains all vertices in S.

There are C(n,k) ways to choose K vertices from the trees. For each of them, let S be the set of the chosen vertices, and find the sum of f(S) over all C(n,k) ways.

Since the answer may be extremely large, print it modulo 924844033(prime).

Since it was too easy for him, he decided to solve this problem for all K=1,2...N.

2≤N≤200000,1≤ai,bi≤N.The given graph is a tree.

Input

The input is given from Standard Input in the following format:
N
a1 b1
a2 b2
...
aN-1 bN-1

Output

Print N lines. The i-th line should contain the answer to the problem where K=i, modulo 924844033.

 

题意:给定一棵 $n$ 个节点的树,选出 $k$ 个特殊点,假设点集为 $S$,令 $f(S)$ 为最小的包含这 $k$ 个节点的连通块,分别求出 $k=1...n$ 在所有情况下的 $f(S)$ 的和。

分析:

考虑暴力,一个点被统计在连通块内,即在以它为根时,选出来的 $k$ 个点都在它的同一个儿子的子树内。即节点 $x$ 被统计进答案的次数 $g(x)$ 为:

$$g(x)=\binom{n}{k}-\sum _{(x,i)\subseteq E}\binom{sz_{i}}{k}$$

令 $cnt_{x}$ 表示上述公式里有多少个 $sz_{i}=x$,那么可以得到:

$$ans_{k}=\sum _{i=1}^{n}cnt_{i}\cdot\binom{i}{k}$$

整理可得:

$$k!\cdot ans_{k}=\sum _{i=1}^{n}\frac{cnt_{i}\cdot i!}{(i-k)!}$$

令 $a_{i}=cnt_{i}\cdot i!$,$b_{i}=(n-i)!$,则可得:

$$k!\cdot ans_{k}=\sum _{i=1}^{n}a_{i}\cdot b_{n-i+k}$$

最终答案为 $n\cdot \binom{n}{k}-ans_{k}$ 。

 #include<cstdio>
#include<algorithm>
#include<cstring>
#define LL long long
using namespace std;
const int N=2e5+;
const int M=+;
const int mod=;
int n,nn,cnt,u,v,ans,first[N],fac[N],inv[N];
int num[N],sz[N],a[M],b[M];
struct edge{int to,next;}e[N*];
int read()
{
int x=,f=;char c=getchar();
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
}
void ins(int u,int v){e[++cnt]=(edge){v,first[u]};first[u]=cnt;}
void dfs(int x,int fa)
{
sz[x]=;
for(int i=first[x];i;i=e[i].next)
{
int to=e[i].to;
if(to==fa)continue;
dfs(to,x);
sz[x]+=sz[to];
}
if(fa!=-)a[sz[x]]++,a[n-sz[x]]++;
}
int power(int a,int b)
{
int ans=;
while(b)
{
if(b&)ans=1ll*ans*a%mod;
a=1ll*a*a%mod;b>>=;
}
return ans;
}
void ntt(int *a,int n,int f)
{
int k=;while((<<k)<n)k++;
for(int i=;i<n;i++)
{
int t=;
for(int j=;j<k;j++)
if(i&(<<j))t|=(<<(k-j-));
if(i<t)swap(a[i],a[t]);
}
for(int l=;l<=n;l<<=)
{
int m=l>>,nw=power(,(mod-)/l);
if(f==-)nw=power(nw,mod-);
for(int *p=a;p!=a+n;p+=l)
{
int w=;
for(int i=;i<m;i++)
{
int t=1ll*p[m+i]*w%mod;
p[m+i]=(p[i]-t+mod)%mod;
p[i]=(p[i]+t)%mod;
w=1ll*w*nw%mod;
}
}
}
if(f==-)
{
int inv=power(n,mod-);
for(int i=;i<n;i++)a[i]=1ll*a[i]*inv%mod;
}
}
int main()
{
n=read();
for(int i=;i<n;i++)
{
u=read();v=read();
ins(u,v);ins(v,u);
}
dfs(,-);
fac[]=;
for(int i=;i<=n;i++)fac[i]=1ll*fac[i-]*i%mod;
inv[n]=power(fac[n],mod-);
for(int i=n;i>=;i--)inv[i-]=1ll*inv[i]*i%mod;
for(int i=;i<=n;i++)a[i]=1ll*a[i]*fac[i]%mod;
for(int i=;i<=n;i++)b[n-i]=inv[i];
nn=;while(nn<n+n+)nn<<=;
ntt(a,nn,);ntt(b,nn,);
for(int i=;i<nn;i++)a[i]=1ll*a[i]*b[i]%mod;
ntt(a,nn,-);
for(int i=;i<=n;i++)
{
ans=1ll*fac[n]*inv[i]%mod*inv[n-i]%mod*n%mod;
printf("%lld\n",(ans-1ll*a[n+i]*inv[i]%mod+mod)%mod);
}
return ;
}

【AGC 005F】Many Easy Problems的更多相关文章

  1. 【AGC005 F】Many Easy Problems

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

  2. 【期望DP】BZOJ3450- Tyvj1952 Easy

    ---恢复内容开始--- [题目大意] 有n次点击要做,成功了就是o,失败了就是x,分数是按comb计算的,连续a个comb就有a*a分,comb就是极大的连续o.求期望分数. [思路] 比之前的OS ...

  3. 【Hello 2018 D】Too Easy Problems

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 可以考虑把所有的题目按照ai排序. 然后顺序考虑最后做出来的题目个数和第i道题目的ai一样. 则1..i-1这些题目就没有用了. 值 ...

  4. 【AGC005F】Many Easy Problems FFT 容斥原理

    题目大意 给你一棵树,有\(n\)个点.还给你了一个整数\(k\). 设\(S\)为树上某些点的集合,定义\(f(S)\)为最小的包含\(S\)的联通子图的大小. \(n\)个点选\(k\)个点一共有 ...

  5. 【AGC005F】Many Easy Problems (NTT)

    Description ​ 给你一棵\(~n~\)个点的树和一个整数\(~k~\).设为\(~S~\)为树上某些点的集合,定义\(~f(S)~\)为最小的包含\(~S~\)的联通子图的大小.\(~n~ ...

  6. 【AGC005F】Many Easy Problems

    Description 题目链接 对于每个\(k\),统计任选\(k\)个点作为关键点的"最小生成树"的大小之和 Solution 正向想法是枚举或者计算大小为\(x\).叶子数目 ...

  7. 【POJ 2826】An Easy Problem?!(几何、线段)

    两个木条装雨水能装多少. 两线段相交,且不遮盖的情况下才可能装到水. 求出交点,再取两线段的较高端点的较小值h,(h-交点的y)为三角形的高. 三角形的宽即为(h带入两条线段所在直线得到的横坐标的差值 ...

  8. 【AGC 002F】Leftmost Ball

    Description Snuke loves colorful balls. He has a total of N*K balls, K in each of his favorite N col ...

  9. 【hdu6334】【2018Multi-University-Training Contest04】Problem C. Problems on a Tree

    维护1边的联通块和2边的联通块,合并的时候直接启发式合并. cdqz的大爷好强啊. #include<bits/stdc++.h> #define lson (o<<1) #d ...

随机推荐

  1. windows server 2012 R2 部署AD域服务

    一.部署AD域控制器 首先,我们检查第一台已经安装Windows Server 2012 R2的服务网络的相关配置,确定的服务器IP地址.子网掩码.默认网关的参数如下,由于该服务器既要充当ADDC角色 ...

  2. 如何在element-UI 组件的change事件中传递自定义参数

    以select为例,如果select写在循环里,触发change事件时可能不只需要传递被选中项的值,还要传递index过去,来改变同一循环中的其他标签的状态. 下面这样写是无效的: @change=& ...

  3. C# 中利用 CRC32 值判断文件是否重复

    需要在 NuGet 中引用 Crc32.NET 包 直接贴代码了: using Force.Crc32; using System; using System.Collections.Generic; ...

  4. [认证授权] 1.OAuth2授权

    1 OAuth2解决什么问题的? 举个栗子先.小明在QQ空间积攒了多年的照片,想挑选一些照片来打印出来.然后小明在找到一家提供在线打印并且包邮的网站(我们叫它PP吧(Print Photo缩写

  5. Nmon实时监控并生成HTML监控报告

    前面的博客介绍了服务端监控工具:Nmon使用方法,最近在github找到了一个nmon自动监控并生成HTML格式报告的工具:easyNmon,使用体验蛮不错的,这里介绍下它的安装及使用方法. 一.关于 ...

  6. java+testng接口测试入门

    testNG是一个测试框架,它能组织测试用例按照你想要的方式进行运行,并输出一定格式的便于阅读的测试报告(结果),通过java+testng的方式说明一下接口测试的基本使用方法. 一.环境搭建 a)千 ...

  7. java中异常处理finally和return的执行顺序

    根据个人亲自测试,得出如下结果: 1.try,catch中有没有return,finnally都会执行,而且是先执行try,catch后,最后执行finnally语句: 2.如果finnally中有r ...

  8. Windows 下使用 工具修改文件的 时间

    1. 下载工具 https://www.cr173.com/soft/12992.html 2. 使用工具修改即可 3. 忘记了东西处理挺方便的.  尤其是往前改日期的时候.

  9. ftm国际化解决方案

    记录一下踩过的坑,在使用ftm:message的时候我发现这个的国际化是依赖于本地浏览器的语言环境的!关于自主设置这个语言的方法有如下3种:(个人建议使用第二种,可以更加灵活且有效!第一种我这边没有生 ...

  10. C语言函数-socket

    int sock = socket(AF_INET, SOCK_STREAM, 0) //建立一个流式套接字,stream是流的意思,Tcp连接,提供序列化的.可靠的.双向连接的字节流.支持带外数据传 ...