Submission #1690864


Source Code Expand

#include <cmath>
#include <ctime>
#include <cstdio>
#include <algorithm>
#define Pi acos(-1.0)

using namespace std;

const int N=8e5+10,Mod=924844033;

struct Edge{ int to,next;} way[N<<1];

int n,num[N],tot,A[N],B[N],P[N],F[N<<4],fact[N],fact_inv[N];

void Build(int a,int b) { way[++tot]=(Edge){b,num[a]}; num[a]=tot; }

void Init()
{
	scanf("%d",&n);
	int a,b;
	for (int i=2;i<=n;++i)
	{
		scanf("%d%d",&a,&b);
		Build(a,b); Build(b,a);
	}
}

int son[N];
void Dfs(int x,int fa)
{
	son[x]=1;
	for (int i=num[x];i;i=way[i].next)
	{
		int v=way[i].to;
		if (v==fa) continue;
		Dfs(v,x);
		son[x]+=son[v];
		A[son[v]]--;
	}
	if (n-son[x]) A[n-son[x]]--;
}

int R[N<<2],L;
int inv(int x)
{
	int t=Mod-2,ret=1;
	while (t)
	{
		if (t&1) ret=1ll*ret*x%Mod;
		x=1ll*x*x%Mod;
		t>>=1;
	}
	return ret;
}

int qpow(int x,int k)
{
	int ret=1;
	while (k)
	{
		if (k&1) ret=1ll*ret*x%Mod;
		x=1ll*x*x%Mod;
		k>>=1;
	}
	return ret;
}

void BRC(int *y,int len)
{
	for (int i=0;i<len;++i) 
		if (R[i]<i) swap(y[i],y[R[i]]);
}

void ntt(int *y,int len,int f)
{
	BRC(y,len);
	fprintf(stderr,"%d\n",clock());
	for (int h=2;h<=len;h<<=1)
	{
		int wn=qpow(5,(Mod-1)/h);
		if (f==-1) wn=qpow(wn,Mod-2);
		for (int j=0;j<len;j+=h)
		{
			int w=1;
			for (int k=j;k<j+h/2;++k)
			{
				int u=y[k],t=1ll*w*y[k+h/2]%Mod;
				y[k]=(u+t)%Mod;
				y[k+h/2]=(u-t+Mod)%Mod;
				w=1ll*w*wn%Mod;
			}
		}
	}
    if(f==-1){
        int ny=qpow(len,Mod-2);
        for(int i=0;i<len;i++) 
			y[i]=1ll*y[i]*ny%Mod;
    }
}

void Solve()
{
	Dfs(1,0);A[n]=n; 
	fact[0]=1; for (int i=1;i<=n;++i) fact[i]=1ll*fact[i-1]*i%Mod;
	int ny=inv(fact[n]);fact_inv[n]=ny;
	for (int i=n-1;i;--i) fact_inv[i]=1ll*fact_inv[i+1]*(i+1)%Mod;
	fact_inv[0]=1;
	for (int i=0;i<=n;++i) B[i]=fact_inv[i];
	for (int i=0;i<=n;++i) A[i]=1ll*(A[i]+Mod)*fact[i]%Mod;
	for (int i=0;i<=n;++i) P[i]=A[n-i];
	
	int len,L=0; for (len=1;len<((n+1)<<1);len<<=1) ++L;
    for(int i=0;i<len;i++)R[i]=R[i>>1]>>1|((i&1)<<(L-1));
	ntt(P,len,1); ntt(B,len,1); 
    for(int i=0;i<len;i++)F[i]=1ll*P[i]*B[i]%Mod;
//    for (int i=0;i<len;++i) printf("%d%c",F[i],i==len-1?'\n':' ');
    ntt(F,len,-1);
	for (int i=n-1;i>=0;--i) 
		printf("%lld\n",1ll*F[i]*fact_inv[n-i]%Mod);
}

int main()
{
	Init();
	Solve();
	return 0;
}

Submission Info

Submission Time
Task F - Many Easy Problems
User Mcallor
Language C++14 (GCC 5.4.1)
Score 1900
Code Size 2370 Byte
Status AC
Exec Time 197 ms
Memory 42752 KB

Compile Error

./Main.cpp: In function ‘void ntt(int*, int, int)’:
./Main.cpp:77:31: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘clock_t {aka long int}’ [-Wformat=]
  fprintf(stderr,"%d\n",clock());
                               ^
./Main.cpp: In function ‘void Init()’:
./Main.cpp:19:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
./Main.cpp:23:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&a,&b);
                      ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1900 / 1900
Status
AC × 3
AC × 48
Set Name Test Cases
Sample example0, example1, example2
All doublestar0, doublestar1, doublestar2, doublestar3, doublestar4, example0, example1, example2, line0, line1, line2, line3, line4, maxrand0, maxrand1, maxrand10, maxrand11, maxrand12, maxrand13, maxrand14, maxrand15, maxrand16, maxrand17, maxrand18, maxrand19, maxrand2, maxrand3, maxrand4, maxrand5, maxrand6, maxrand7, maxrand8, maxrand9, rand0, rand1, rand2, rand3, rand4, rand5, rand6, rand7, rand8, rand9, star0, star1, star2, star3, star4
Case Name Status Exec Time Memory
doublestar0 AC 189 ms 34816 KB
doublestar1 AC 189 ms 34816 KB
doublestar2 AC 189 ms 34816 KB
doublestar3 AC 189 ms 34816 KB
doublestar4 AC 189 ms 34816 KB
example0 AC 6 ms 18560 KB
example1 AC 6 ms 18560 KB
example2 AC 6 ms 18560 KB
line0 AC 197 ms 42752 KB
line1 AC 197 ms 42752 KB
line2 AC 197 ms 42752 KB
line3 AC 197 ms 42752 KB
line4 AC 197 ms 42752 KB
maxrand0 AC 196 ms 34816 KB
maxrand1 AC 196 ms 34816 KB
maxrand10 AC 196 ms 34816 KB
maxrand11 AC 196 ms 34816 KB
maxrand12 AC 196 ms 34816 KB
maxrand13 AC 196 ms 34816 KB
maxrand14 AC 196 ms 34816 KB
maxrand15 AC 196 ms 34816 KB
maxrand16 AC 196 ms 34816 KB
maxrand17 AC 196 ms 34816 KB
maxrand18 AC 196 ms 34816 KB
maxrand19 AC 196 ms 34816 KB
maxrand2 AC 196 ms 34816 KB
maxrand3 AC 196 ms 34816 KB
maxrand4 AC 196 ms 34816 KB
maxrand5 AC 196 ms 34816 KB
maxrand6 AC 196 ms 34816 KB
maxrand7 AC 196 ms 34816 KB
maxrand8 AC 196 ms 34816 KB
maxrand9 AC 197 ms 34816 KB
rand0 AC 8 ms 18688 KB
rand1 AC 6 ms 18560 KB
rand2 AC 7 ms 18688 KB
rand3 AC 8 ms 18688 KB
rand4 AC 6 ms 18560 KB
rand5 AC 8 ms 18688 KB
rand6 AC 7 ms 18688 KB
rand7 AC 8 ms 18688 KB
rand8 AC 6 ms 18560 KB
rand9 AC 7 ms 18560 KB
star0 AC 186 ms 34816 KB
star1 AC 186 ms 34816 KB
star2 AC 186 ms 34816 KB
star3 AC 186 ms 34816 KB
star4 AC 192 ms 34816 KB