[Gdgzezoi] Problem B: simple question Many Easy Problems

Description
One day, Aoki to the question Takahashi:

  • Given a tree has N nodes, and an integer from 1 to K. These nodes N numerals edge is expressed as an integer pair (ai, bi).
  • For a set of points S, we define F (S) S represents a number of nodes comprising the smallest sub-tree all nodes. (Subtree is defined as a connected subgraph of the original tree)
  • We have (nk) species selected K nodes in the entire tree program. For all of these programs, we denote the set of selected nodes with S, you find all the (nk) sets of f (S) and the The answer to 924 844 033 (prime number) modulo.

Takahashi feel stupid question, so he decides to obtain K = 1,2, ⋯ N of all the answers.
The Input
first line of an integer n, n-1 the next lines of two integers ai, bi.

The Output
N rows represent the i-th row when the number K = I answer mode 924,844,033 obtained when i.
The Sample the Input
Sample INPUT. 1:
. 3
. 1 2
2. 3

sample input 2:
4
1 2
1 3
1 4

sample input 3:
7
1 2
2 3
2 4
4 5
4 6
6 7
Sample Output
sample output 1:
3
7
3

sample output 2:
4
15
13
4

sample output 3:
7
67
150
179
122
45
7
HINT

Sample 1 when K = 2 as the answer FIG.

Data are met:

  • 2≤N≤2×105
  • 1≤ai,bi≤N
  • Tree is given in FIG.

There are about 27 points to meet n≤2700. . ?

Thinking

Be apparent after first considering the contribution of each point of the re-repellent capacity, it becomes a request for each x Σmk = 1 (ckx), where m = 2 * (n-1), ck is a child of both sides of each edge tree size.

Noted ck≤n, so after the same ck bonded together, becomes Σnk = 1 ck (k / x) = 1 / x! Σk ckk! / (K-x)!

Found to be convolution, NTT directly on the line.

Code

#include<bits/stdc++.h>
#define ll long long
#define N 800077
#define mod 924844033
#define G 5
#define unG 554906420
using namespace std;
int n;
struct edge{int v,nxt;}e[N<<1];
int hd[N],cnt;
inline void add(int u, int v){e[++cnt]=(edge){v,hd[u]}, hd[u]=cnt;}
int power(int x, int y)
{
    int ret=1;
    while(y)
    {
        if(y&1) ret=(ll)ret*x%mod;
        x=(ll)x*x%mod;
        y>>=1;
    }
    return ret;
}
int siz[N],num[N];
void dfs(int u, int fa){
    siz[u]=1;
    for(int i=hd[u]; i; i=e[i].nxt) if(e[i].v!=fa){
        dfs(e[i].v,u);
        siz[u]+=siz[e[i].v];
        --num[siz[e[i].v]], --num[n-siz[e[i].v]];
    }
}
int fac[N],unfac[N];
int a[N],b[N],c[N];
struct Poly
{
    int n,bit,r[N];
    void init(int x)
    {
        for(n=1, bit=0; n<=x; n<<=1, ++bit);
        for(int i=1; i<n; ++i) r[i] = (r[i>>1]>>1) | ((i&1)<<(bit-1));
    }
    void dft(int *a, int f)
    {
        for(int i=0; i<n; ++i) if(i<r[i]) swap(a[i],a[r[i]]);
        for(int i=1; i<n; i<<=1)
        {
            int wn = power(f==1 ? G : unG, (mod-1)/(i<<1));
            for(int j=0; j<n; j+=(i<<1)){
                int w=1, x, y;
                for(int k=0; k<i; ++k, w=(ll)w*wn%mod)
                    x=a[j+k], y=(ll)w*a[j+i+k]%mod,
                    a[j+k]=(x+y)%mod, a[j+i+k]=(x-y+mod)%mod;
            }
        }
        if(f==-1)
        {
            int tmp=power(n,mod-2);
            for(int i=0; i<n; ++i) a[i]=(ll)a[i]*tmp%mod;
        }
    }
}NTT;
int main()
{
    scanf("%d",&n);
    for(int i=1,u,v; i<n; ++i) scanf("%d%d",&u,&v),add(u,v),add(v,u);
    fac[0]=1;
    for(int i=1; i<=n; ++i) fac[i]=(ll)fac[i-1]*i%mod;
    unfac[n]=power(fac[n],mod-2);
    for(int i=n-1; i>=0; --i) unfac[i]=(ll)unfac[i+1]*(i+1)%mod;
    dfs(1,0);
    num[n]=n;
    for(int i=0; i<=n; ++i)
        b[i]=((ll)num[n-i]*fac[n-i]%mod+mod)%mod,
        c[i]=unfac[i];
    NTT.init(n*2+1), NTT.dft(b,1), NTT.dft(c,1);
    for(int i=0; i<NTT.n; ++i) a[i]=(ll)b[i]*c[i]%mod;
    NTT.dft(a,-1);
    for(int i=1; i<=n; ++i) printf("%lld\n",(ll)a[n-i]*unfac[i]%mod);
}


Published 703 original articles · won praise 392 · Views 140,000 +

Guess you like

Origin blog.csdn.net/Eric1561759334/article/details/100786759