Problem p03991 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define reg register
#define mod 924844033
#define G 5
#define Gi 554906420
#define maxn 500001
using namespace std;
inline int read() {
  reg int s = 0, t = 0;
  reg char ch = getchar();
  while (ch > '9' || ch < '0')
    t |= ch == '-', ch = getchar();
  while (ch >= '0' && ch <= '9')
    s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
  return t ? -s : s;
}
int inv[maxn], fac[maxn], ifac[maxn], nt[maxn], fi[maxn], go[maxn];
int lim, rev[maxn], cnt, siz[maxn], n, f[maxn], g[maxn];
int ksm(int u, int v) {
  int s = 1;
  for (int i = v; i; i >>= 1) {
    if (i & 1)
      s = 1ll * s * u % mod;
    u = 1ll * u * u % mod;
  }
  return s;
}
void add(int u, int v) {
  nt[++cnt] = fi[u];
  fi[u] = cnt;
  go[cnt] = v;
}
int C(int x, int y) {
  if (x < 0 || y < 0 || x < y)
    return 0;
  else
    return 1ll * fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}
void dfs(int u, int fa) {
  siz[u] = 1;
  for (int i = fi[u]; i; i = nt[i]) {
    int v = go[i];
    if (v == fa)
      continue;
    dfs(v, u);
    siz[u] += siz[v];
  }
  f[siz[u]]++;
  f[n - siz[u]]++;
}
void ntt(int *a, int type) {
  for (int i = 1; i < lim; i++)
    if (i < rev[i])
      swap(a[i], a[rev[i]]);
  for (int i = 1; i < lim; i <<= 1) {
    int x = ksm(type == 1 ? G : Gi, (mod - 1) / (i << 1));
    for (int j = 0; j < lim; j += (i << 1)) {
      int y = 1;
      for (int k = 0; k < i; k++, y = 1ll * y * x % mod) {
        int p = a[j + k], q = 1ll * y * a[j + k + i] % mod;
        a[j + k] = (p + q) % mod, a[j + k + i] = (p - q + mod) % mod;
      }
    }
  }
}
int main() {
  n = read();
  for (int i = 1; i < n; i++) {
    int x = read(), y = read();
    add(x, y);
    add(y, x);
  }
  dfs(1, 0);
  fac[0] = 1;
  ifac[0] = 1;
  inv[0] = 1;
  for (int i = 1; i < maxn; i++) {
    inv[i] = (i == 1) ? 1 : 1ll * inv[mod % i] * (mod - mod / i) % mod;
    fac[i] = 1ll * fac[i - 1] * i % mod;
    ifac[i] = 1ll * ifac[i - 1] * inv[i] % mod;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    f[i] = 1ll * f[i] * fac[i] % mod;
  for (int i = 0; i <= n; i++)
    g[i] = ifac[i];
  reverse(f, f + n + 1);
  int len = 0;
  for (lim = 1; lim <= (n << 1); lim <<= 1, len++)
    ;
  for (int i = 1; i < lim; i++)
    rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (len - 1));
  ntt(g, 1);
  ntt(f, 1);
  for (int i = 0; i < lim; i++)
    g[i] = 1ll * g[i] * f[i] % mod;
  ntt(g, -1);
  for (int i = 0; i < lim; i++)
    g[i] = 1ll * g[i] * ksm(lim, mod - 2) % mod;
  reverse(g, g + n + 1);
  for (int i = 1; i <= n; i++) {
    ans = 1ll * (n + 1) * C(n, i) % mod;
    ans = (ans - 1ll * g[i] * ifac[i] % mod + mod) % mod;
    printf("%d\n", ans);
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define reg register
#define mod 924844033
#define G 5
#define Gi 554906420
#define maxn 2000001
using namespace std;
inline int read() {
  reg int s = 0, t = 0;
  reg char ch = getchar();
  while (ch > '9' || ch < '0')
    t |= ch == '-', ch = getchar();
  while (ch >= '0' && ch <= '9')
    s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
  return t ? -s : s;
}
int inv[maxn], fac[maxn], ifac[maxn], nt[maxn], fi[maxn], go[maxn];
int lim, rev[maxn], cnt, siz[maxn], n, f[maxn], g[maxn];
int ksm(int u, int v) {
  int s = 1;
  for (int i = v; i; i >>= 1) {
    if (i & 1)
      s = 1ll * s * u % mod;
    u = 1ll * u * u % mod;
  }
  return s;
}
void add(int u, int v) {
  nt[++cnt] = fi[u];
  fi[u] = cnt;
  go[cnt] = v;
}
int C(int x, int y) {
  if (x < 0 || y < 0 || x < y)
    return 0;
  else
    return 1ll * fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}
void dfs(int u, int fa) {
  siz[u] = 1;
  for (int i = fi[u]; i; i = nt[i]) {
    int v = go[i];
    if (v == fa)
      continue;
    dfs(v, u);
    siz[u] += siz[v];
  }
  f[siz[u]]++;
  f[n - siz[u]]++;
}
void ntt(int *a, int type) {
  for (int i = 1; i < lim; i++)
    if (i < rev[i])
      swap(a[i], a[rev[i]]);
  for (int i = 1; i < lim; i <<= 1) {
    int x = ksm(type == 1 ? G : Gi, (mod - 1) / (i << 1));
    for (int j = 0; j < lim; j += (i << 1)) {
      int y = 1;
      for (int k = 0; k < i; k++, y = 1ll * y * x % mod) {
        int p = a[j + k], q = 1ll * y * a[j + k + i] % mod;
        a[j + k] = (p + q) % mod, a[j + k + i] = (p - q + mod) % mod;
      }
    }
  }
}
int main() {
  n = read();
  for (int i = 1; i < n; i++) {
    int x = read(), y = read();
    add(x, y);
    add(y, x);
  }
  dfs(1, 0);
  fac[0] = 1;
  ifac[0] = 1;
  inv[0] = 1;
  for (int i = 1; i < maxn; i++) {
    inv[i] = (i == 1) ? 1 : 1ll * inv[mod % i] * (mod - mod / i) % mod;
    fac[i] = 1ll * fac[i - 1] * i % mod;
    ifac[i] = 1ll * ifac[i - 1] * inv[i] % mod;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    f[i] = 1ll * f[i] * fac[i] % mod;
  for (int i = 0; i <= n; i++)
    g[i] = ifac[i];
  reverse(f, f + n + 1);
  int len = 0;
  for (lim = 1; lim <= (n << 1); lim <<= 1, len++)
    ;
  for (int i = 1; i < lim; i++)
    rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (len - 1));
  ntt(g, 1);
  ntt(f, 1);
  for (int i = 0; i < lim; i++)
    g[i] = 1ll * g[i] * f[i] % mod;
  ntt(g, -1);
  for (int i = 0; i < lim; i++)
    g[i] = 1ll * g[i] * ksm(lim, mod - 2) % mod;
  reverse(g, g + n + 1);
  for (int i = 1; i <= n; i++) {
    ans = 1ll * (n + 1) * C(n, i) % mod;
    ans = (ans - 1ll * g[i] * ifac[i] % mod + mod) % mod;
    printf("%d\n", ans);
  }
}