Submission #2381519


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const ll MOD = 924844033;

struct NumberTheoreticTransform {
    int mod;
    int root;

    NumberTheoreticTransform(int mod, int root) : mod(mod), root(root) {}

    int mul(int x, int y) {
        return int64_t(x) * y % mod;
    }

    int add(int x, int y) {
        return (x += y) >= mod ? x - mod : x;
    }

    int pow(int x, int y) {
        int res = 1;
        while (y > 0) {
            if (y & 1) res = mul(res, x);
            x = mul(x, x);
            y >>= 1;
        }
        return res;
    }

    int inv(int x) {
        return pow(x, mod - 2);
    }

    void ntt(std::vector<int> &a, bool rev = false) {
        int n = a.size();
        int h = 0;
        for (int i = 0; 1 << i < n; i++) h++;
        for (int i = 0; i < n; i++) {
            int j = 0;
            for (int k = 0; k < h; k++) {
            	j |= (i >> k & 1) << (h - 1 - k);
            }
            if (i < j) std::swap(a[i], a[j]);
        }
        for (int i = 1; i < n; i *= 2) {
            int w = pow(root, (mod - 1) / (i * 2));
            if (rev) w = inv(w);
            for (int j = 0; j < n; j += i * 2) {
                int wn = 1;
                for (int k = 0; k < i; k++) {
                    int s = a[j + k + 0];
                    int t = mul(a[j + k + i], wn);
                    a[j + k + 0] = add(s, t);
                    a[j + k + i] = add(s, mod - t);
                    wn = mul(wn, w);
                }
            }
        }
        int v = inv(n);
        if (rev) for (int i = 0; i < n; i++) a[i] = mul(a[i], v);
    }

    std::vector<int> mul(std::vector<int> a, std::vector<int> b) {
        int s = a.size() + b.size() - 1;
        int t = 1;
        while (t < s) t *= 2;
        a.resize(t);
        b.resize(t);
        ntt(a);
        ntt(b);
        for (int i = 0; i < t; i++) {
            a[i] = mul(a[i], b[i]);
        }
        ntt(a, true);

        a.resize(s);
        return a;
    }
};

const int MN = 400010;

int N;
vi g[MN];
int num[MN], sz[MN];
ll fac[MN], ifac[MN], inv[MN];

void dfs(int v, int p)
{
	sz[v] = 1;
	for (int to : g[v]) if (to != p) {
		dfs(to, v);
		sz[v] += sz[to];
		++num[sz[to]];
	}
	if (p != -1) {
		++num[N - sz[v]];
	}
}

int main() {
	inv[1] = 1;
    for (int i = 2; i < MN; ++i) {
        inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;	
    }
	fac[0] = ifac[0] = 1;

	for (int i = 1; i < MN; ++i) {
		fac[i] = fac[i-1] * i % MOD;
		ifac[i] = ifac[i-1] * inv[i] % MOD;
	}

	cin >> N;

	rep(i, N-1) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		g[a].pb(b); g[b].pb(a);
	}

	dfs(0, -1);

	vi a(N+1), b(N+1);

	rep(i, N+1) {
		a[i] = (ll)num[i] * fac[i] % MOD;
		b[i] = ifac[N-i];
	}

    NumberTheoreticTransform ntt(MOD, 5);

    a = ntt.mul(a, b);

    for (int i = 1; i <= N; ++i) {
    	ll x = a[N + i] * ifac[i] % MOD;
    	ll t = N * fac[N] % MOD * ifac[i] % MOD * ifac[N-i] % MOD;
    	t -= x;
    	if (t < 0) t += MOD;
    	cout << t << endl;
    }

    return 0;
}

Submission Info

Submission Time
Task F - Many Easy Problems
User satashun
Language C++14 (GCC 5.4.1)
Score 1900
Code Size 3445 Byte
Status AC
Exec Time 653 ms
Memory 45428 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 592 ms 35180 KB
doublestar1 AC 590 ms 35180 KB
doublestar2 AC 593 ms 35180 KB
doublestar3 AC 591 ms 35180 KB
doublestar4 AC 593 ms 35180 KB
example0 AC 19 ms 22144 KB
example1 AC 19 ms 22144 KB
example2 AC 19 ms 22144 KB
line0 AC 616 ms 45428 KB
line1 AC 613 ms 45300 KB
line2 AC 619 ms 45424 KB
line3 AC 625 ms 45300 KB
line4 AC 612 ms 45428 KB
maxrand0 AC 627 ms 35056 KB
maxrand1 AC 631 ms 35056 KB
maxrand10 AC 624 ms 35056 KB
maxrand11 AC 623 ms 35056 KB
maxrand12 AC 643 ms 35056 KB
maxrand13 AC 629 ms 35056 KB
maxrand14 AC 625 ms 35056 KB
maxrand15 AC 647 ms 35056 KB
maxrand16 AC 626 ms 35056 KB
maxrand17 AC 644 ms 35056 KB
maxrand18 AC 629 ms 35056 KB
maxrand19 AC 632 ms 35056 KB
maxrand2 AC 624 ms 35056 KB
maxrand3 AC 641 ms 35056 KB
maxrand4 AC 653 ms 35056 KB
maxrand5 AC 629 ms 35056 KB
maxrand6 AC 633 ms 35056 KB
maxrand7 AC 620 ms 35056 KB
maxrand8 AC 622 ms 35056 KB
maxrand9 AC 626 ms 35056 KB
rand0 AC 27 ms 22400 KB
rand1 AC 19 ms 22144 KB
rand2 AC 24 ms 22272 KB
rand3 AC 26 ms 22272 KB
rand4 AC 21 ms 22144 KB
rand5 AC 26 ms 22400 KB
rand6 AC 24 ms 22272 KB
rand7 AC 26 ms 22272 KB
rand8 AC 20 ms 22144 KB
rand9 AC 22 ms 22272 KB
star0 AC 582 ms 35560 KB
star1 AC 577 ms 35560 KB
star2 AC 572 ms 35556 KB
star3 AC 580 ms 35560 KB
star4 AC 587 ms 35560 KB