Submission #1470810


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long int ll;
#define int long long
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PLL, PLL> PP;
typedef pair <PII, int> PPI;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const int inf = 1e9+9;
const int mod = 924844033;
const int N = (1 << 20);
const int lg = 20;
int rev[N];

inline ll potmod(ll a, ll b)
{
	ll res = 1;
	while (b)
	{
		if (b & 1) res = (res * a)%mod;
		a = (a * a)%mod;
		b >>= 1;
	}
	return res;
}

void compute(int bit = lg - 1, int x = 0, int y = 0)
{
	if (bit == -1)
	{
		rev[y] = x;
		return;
	}
	compute(bit - 1, x, y);
	compute(bit - 1, x + (1 << bit), y + (1 << (lg - bit - 1)));
}

void NTT(int a[], bool inverse)
{
	FOR(i, 0, N-1)
		if (rev[i] > i) swap(a[rev[i]], a[i]);
	
	for (int len = 2; len <= N; len *= 2)
	{
		int wn = potmod(3, (mod -1)/len/2);
		if (inverse) wn = potmod(wn, mod - 2);
		for (int j=0; j<N; j+=len)
		{
			int w = 1;
			for (int x = j, y = j + len / 2; y < j + len; ++x, ++y) 
			{
				int u = a[x], v = (ll)a[y] * w % mod;
				a[x] = u + v;
				a[y] = u - v + mod;
				while (a[x] >= mod) a[x] -= mod;
				while (a[y] >= mod) a[y] -= mod;
				w = (ll)w * wn % mod;
			}
		}
	}	
	
	if (inverse)
	{
		ll w = potmod(N, mod - 2);
		FOR(i, 0, N-1) a[i] = (ll)a[i] * w % mod;
	}
}

ll fac[N], invfac[N];
int n, a[N], b[N], c[N], sz[N], res[N];
vector <int> adj[N];
void dfs(int x, int p = 0)
{
	sz[x] = 1;
	for (auto u : adj[x])
		if (u != p)
		{
			dfs(u, x);
			sz[x] += sz[u];
		}
	a[sz[x]]++;
	a[n - sz[x]]++;
}
int32_t main()
{
	boost;
	compute();
	fac[0] = 1, invfac[0] = 1;
	FOR(i, 1, N-1) fac[i] = (fac[i-1] * i)%mod;
	invfac[N-1] = potmod(fac[N-1], mod - 2);
	for (int i=N-2; i>0; --i) invfac[i] = invfac[i + 1] * (i + 1)%mod;
	cin >> n;
	FOR(i, 2, n)
	{
		int aa, bb;
		cin >> aa >> bb;
		adj[aa].pb(bb);
		adj[bb].pb(aa);
	}
	dfs(1);
	FOR(i, 0, N-1) a[i] = (ll)a[i] * fac[i] % mod;
	int maxn = (1 << 18);
	for (int i=maxn; i>=0; --i) b[i] = invfac[maxn - i];
	NTT(a, false);
	NTT(b, false);
	FOR(i, 0, N-1) c[i] = (ll)a[i] * b[i] % mod;
	NTT(c, true);
	FOR(i, 0, maxn-1) res[i] = c[i + maxn];
	FOR(i, 1, n) cout << invfac[i] * ((fac[n] * (n + 1) % mod * invfac[n - i] %mod -res[i] + mod) % mod)%mod << "\n";
}

Submission Info

Submission Time
Task F - Many Easy Problems
User Miyukine
Language C++14 (GCC 5.4.1)
Score 1900
Code Size 2716 Byte
Status AC
Exec Time 663 ms
Memory 96640 KB

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 566 ms 89076 KB
doublestar1 AC 564 ms 89076 KB
doublestar2 AC 564 ms 89076 KB
doublestar3 AC 564 ms 89076 KB
doublestar4 AC 564 ms 89076 KB
example0 AC 487 ms 80128 KB
example1 AC 487 ms 80128 KB
example2 AC 493 ms 80128 KB
line0 AC 663 ms 96640 KB
line1 AC 662 ms 96640 KB
line2 AC 661 ms 96640 KB
line3 AC 661 ms 96640 KB
line4 AC 661 ms 96640 KB
maxrand0 AC 645 ms 89600 KB
maxrand1 AC 635 ms 89600 KB
maxrand10 AC 636 ms 89600 KB
maxrand11 AC 638 ms 89600 KB
maxrand12 AC 636 ms 89600 KB
maxrand13 AC 640 ms 89600 KB
maxrand14 AC 636 ms 89600 KB
maxrand15 AC 636 ms 89600 KB
maxrand16 AC 635 ms 89600 KB
maxrand17 AC 637 ms 89472 KB
maxrand18 AC 638 ms 89600 KB
maxrand19 AC 636 ms 89600 KB
maxrand2 AC 636 ms 89600 KB
maxrand3 AC 638 ms 89600 KB
maxrand4 AC 635 ms 89600 KB
maxrand5 AC 637 ms 89600 KB
maxrand6 AC 636 ms 89600 KB
maxrand7 AC 642 ms 89600 KB
maxrand8 AC 636 ms 89600 KB
maxrand9 AC 642 ms 89600 KB
rand0 AC 522 ms 80256 KB
rand1 AC 508 ms 80128 KB
rand2 AC 522 ms 80256 KB
rand3 AC 532 ms 80384 KB
rand4 AC 518 ms 80128 KB
rand5 AC 524 ms 80256 KB
rand6 AC 521 ms 80256 KB
rand7 AC 522 ms 80256 KB
rand8 AC 515 ms 80128 KB
rand9 AC 518 ms 80256 KB
star0 AC 556 ms 89840 KB
star1 AC 558 ms 89840 KB
star2 AC 563 ms 89840 KB
star3 AC 558 ms 89968 KB
star4 AC 556 ms 89840 KB