Problem p03991 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1e5 + 5, MOD = 924844033, g = 5;

int n, u, v, lim, cnt = 0;
int a[MAXN], b[MAXN], h[MAXN], siz[MAXN], fac[MAXN], r[MAXN];

struct edge {
  int v, nxt;
} E[MAXN * 2];

void add_edge(int u, int v) {
  E[cnt].v = v;
  E[cnt].nxt = h[u];
  h[u] = cnt++;
}

int fpow(int a, int n) {
  int rtn = 1;
  for (; n; n >>= 1, a = 1ll * a * a % MOD)
    if (n & 1)
      rtn = 1ll * rtn * a % MOD;
  return rtn;
}

int inv(int x) { return fpow(x, MOD - 2); }

void dfs(int cur, int fa) {
  for (int i = h[cur]; ~i; i = E[i].nxt) {
    int v = E[i].v;
    if (v == fa)
      continue;
    dfs(v, cur);
    siz[cur] += siz[v];
    a[siz[v]]--;
  }
  siz[cur]++;
  a[n - siz[cur]]--;
  a[n]++;
}

void init() {
  fac[0] = 1;
  for (int i = 1; i <= n; i++)
    fac[i] = 1ll * fac[i - 1] * i % MOD;
  for (int i = 0; i <= n; i++)
    a[i] = 1ll * (a[i] % MOD + MOD) % MOD * fac[i] % MOD;
  for (int i = 0; i <= n; i++)
    b[n - i] = inv(fac[i]);
  lim = 1;
  while (lim <= n * 2)
    lim <<= 1;
  for (int i = 1; i < lim; i++)
    r[i] = (r[i >> 1] >> 1) | (i & 1 ? lim >> 1 : 0);
}

void ntt(int *f, bool p = 0) {
  for (int i = 1; i < lim; i++)
    if (i < r[i])
      swap(f[i], f[r[i]]);
  for (int i = 2; i <= lim; i <<= 1) {
    int len = i >> 1;
    int ur = fpow(g, (MOD - 1) / i);
    if (p)
      ur = inv(ur);
    for (int j = 0; j < lim; j += i) {
      int tmp = 1;
      for (int k = j; k < j + len; k++) {
        int t = 1ll * tmp * f[k + len] % MOD;
        f[k + len] = f[k] - t;
        f[k] = f[k] + t;
        if (f[k] >= MOD)
          f[k] -= MOD;
        if (f[k + len] < 0)
          f[k + len] += MOD;
        tmp = 1ll * tmp * ur % MOD;
      }
    }
  }
  if (p) {
    int tmp = inv(lim);
    for (int i = 0; i < lim; i++)
      f[i] = 1ll * f[i] * tmp % MOD;
  }
}

int main() {
  cin >> n;
  memset(h, -1, sizeof(h));
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    add_edge(u, v);
    add_edge(v, u);
  }
  dfs(1, 0);
  init();
  ntt(a);
  ntt(b);
  for (int i = 0; i < lim; i++)
    a[i] = 1ll * a[i] * b[i] % MOD;
  ntt(a, 1);
  // for(int i = 0; i < lim; i++)
  //     cout<<a[i]<<' ';cout<<endl;
  for (int i = 1; i <= n; i++)
    cout << 1ll * inv(fac[i]) * a[i + n] % MOD << endl;
  return 0;
}

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

const int MAXN = 1e6 + 5, MOD = 924844033, g = 5;

int n, u, v, lim, cnt = 0;
int a[MAXN], b[MAXN], h[MAXN], siz[MAXN], fac[MAXN], r[MAXN];

struct edge {
  int v, nxt;
} E[MAXN * 2];

void add_edge(int u, int v) {
  E[cnt].v = v;
  E[cnt].nxt = h[u];
  h[u] = cnt++;
}

int fpow(int a, int n) {
  int rtn = 1;
  for (; n; n >>= 1, a = 1ll * a * a % MOD)
    if (n & 1)
      rtn = 1ll * rtn * a % MOD;
  return rtn;
}

int inv(int x) { return fpow(x, MOD - 2); }

void dfs(int cur, int fa) {
  for (int i = h[cur]; ~i; i = E[i].nxt) {
    int v = E[i].v;
    if (v == fa)
      continue;
    dfs(v, cur);
    siz[cur] += siz[v];
    a[siz[v]]--;
  }
  siz[cur]++;
  a[n - siz[cur]]--;
  a[n]++;
}

void init() {
  fac[0] = 1;
  for (int i = 1; i <= n; i++)
    fac[i] = 1ll * fac[i - 1] * i % MOD;
  for (int i = 0; i <= n; i++)
    a[i] = 1ll * (a[i] % MOD + MOD) % MOD * fac[i] % MOD;
  for (int i = 0; i <= n; i++)
    b[n - i] = inv(fac[i]);
  lim = 1;
  while (lim <= n * 2)
    lim <<= 1;
  for (int i = 1; i < lim; i++)
    r[i] = (r[i >> 1] >> 1) | (i & 1 ? lim >> 1 : 0);
}

void ntt(int *f, bool p = 0) {
  for (int i = 1; i < lim; i++)
    if (i < r[i])
      swap(f[i], f[r[i]]);
  for (int i = 2; i <= lim; i <<= 1) {
    int len = i >> 1;
    int ur = fpow(g, (MOD - 1) / i);
    if (p)
      ur = inv(ur);
    for (int j = 0; j < lim; j += i) {
      int tmp = 1;
      for (int k = j; k < j + len; k++) {
        int t = 1ll * tmp * f[k + len] % MOD;
        f[k + len] = f[k] - t;
        f[k] = f[k] + t;
        if (f[k] >= MOD)
          f[k] -= MOD;
        if (f[k + len] < 0)
          f[k + len] += MOD;
        tmp = 1ll * tmp * ur % MOD;
      }
    }
  }
  if (p) {
    int tmp = inv(lim);
    for (int i = 0; i < lim; i++)
      f[i] = 1ll * f[i] * tmp % MOD;
  }
}

int main() {
  cin >> n;
  memset(h, -1, sizeof(h));
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    add_edge(u, v);
    add_edge(v, u);
  }
  dfs(1, 0);
  init();
  ntt(a);
  ntt(b);
  for (int i = 0; i < lim; i++)
    a[i] = 1ll * a[i] * b[i] % MOD;
  ntt(a, 1);
  // for(int i = 0; i < lim; i++)
  //     cout<<a[i]<<' ';cout<<endl;
  for (int i = 1; i <= n; i++)
    cout << 1ll * inv(fac[i]) * a[i + n] % MOD << endl;
  return 0;
}