Problem p03991 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  register int x = 0;
  register char ch = getchar();
  while (ch < '0' || ch > '9')
    ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = x * 10 + (ch ^ 48), ch = getchar();
  return x;
}
const int N = 1e5 + 5;
const int P = 924844033;
long long Inv, g[N], f[N], fac[N], inv[N];
int n, m, now, len, v[N], r[N], si[N], nex[N], head[N];
void addedges(int x, int y) {
  nex[++now] = head[x];
  head[x] = now, v[now] = y;
}
long long C(int n, int m) { return fac[n] * inv[m] % P * inv[n - m] % P; }
long long fsp(long long x, int y) {
  long long ans = 1;
  while (y) {
    if (y & 1)
      ans = ans * x % P;
    x = x * x % P, y >>= 1;
  }
  return ans;
}
void NTT(long long *d, int f) {
  for (int i = 1; i < n; i++)
    if (i < r[i])
      swap(d[i], d[r[i]]);
  for (int i = 1; i < n; i <<= 1) {
    int wn = fsp(5, (P - 1) / (i << 1));
    if (f)
      wn = fsp(wn, P - 2);
    for (int j = 0; j < n; j += i << 1) {
      long long w = 1;
      for (int k = 0; k < i; k++, w = w * wn % P) {
        int x = d[j + k], y = w * d[i + j + k] % P;
        d[j + k] = (x + y) % P, d[i + j + k] = (x - y + P) % P;
      }
    }
  }
  if (f)
    for (int i = 0; i < n; i++)
      d[i] = d[i] * Inv % P;
}
void dfs(int x, int fa) {
  for (int i = head[x]; i; i = nex[i])
    if (v[i] != fa)
      dfs(v[i], x), si[x] += si[v[i]];
  si[x]++, ++f[n - si[x]];
  for (int i = head[x]; i; i = nex[i])
    if (v[i] != fa)
      ++f[si[v[i]]];
}
int main() {
  n = read();
  for (int i = 1; i < n; i++) {
    int x = read(), y = read();
    addedges(x, y), addedges(y, x);
  }
  dfs(1, 1), inv[0] = fac[0] = 1, f[0] = 0;
  for (int i = 1; i <= n; i++)
    fac[i] = fac[i - 1] * i % P;
  for (int i = 1; i <= n; i++)
    inv[i] = fsp(fac[i], P - 2);
  for (int i = 0; i <= n; i++)
    f[i] = f[i] * fac[i] % P;
  for (int i = 0; i <= n; i++)
    g[i] = inv[i];
  for (m = n; (1 << len) <= n + n; ++len)
    ;
  n = 1 << len, Inv = fsp(n, P - 2), reverse(f, f + n);
  for (int i = 1; i < n; i++)
    r[i] = (r[i >> 1] >> 1) | ((i & 1) << (len - 1));
  NTT(f, 0), NTT(g, 0);
  for (int i = 0; i < n; i++)
    f[i] = f[i] * g[i] % P;
  NTT(f, 1), reverse(f, f + n);
  for (int i = 1; i <= m; i++)
    printf("%lld\n", (m * C(m, i) - f[i] * inv[i] % P + P) % P);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  register int x = 0;
  register char ch = getchar();
  while (ch < '0' || ch > '9')
    ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = x * 10 + (ch ^ 48), ch = getchar();
  return x;
}
const int N = 1e6 + 5;
const int P = 924844033;
long long Inv, g[N], f[N], fac[N], inv[N];
int n, m, now, len, v[N], r[N], si[N], nex[N], head[N];
void addedges(int x, int y) {
  nex[++now] = head[x];
  head[x] = now, v[now] = y;
}
long long C(int n, int m) { return fac[n] * inv[m] % P * inv[n - m] % P; }
long long fsp(long long x, int y) {
  long long ans = 1;
  while (y) {
    if (y & 1)
      ans = ans * x % P;
    x = x * x % P, y >>= 1;
  }
  return ans;
}
void NTT(long long *d, int f) {
  for (int i = 1; i < n; i++)
    if (i < r[i])
      swap(d[i], d[r[i]]);
  for (int i = 1; i < n; i <<= 1) {
    int wn = fsp(5, (P - 1) / (i << 1));
    if (f)
      wn = fsp(wn, P - 2);
    for (int j = 0; j < n; j += i << 1) {
      long long w = 1;
      for (int k = 0; k < i; k++, w = w * wn % P) {
        int x = d[j + k], y = w * d[i + j + k] % P;
        d[j + k] = (x + y) % P, d[i + j + k] = (x - y + P) % P;
      }
    }
  }
  if (f)
    for (int i = 0; i < n; i++)
      d[i] = d[i] * Inv % P;
}
void dfs(int x, int fa) {
  for (int i = head[x]; i; i = nex[i])
    if (v[i] != fa)
      dfs(v[i], x), si[x] += si[v[i]];
  si[x]++, ++f[n - si[x]];
  for (int i = head[x]; i; i = nex[i])
    if (v[i] != fa)
      ++f[si[v[i]]];
}
int main() {
  n = read();
  for (int i = 1; i < n; i++) {
    int x = read(), y = read();
    addedges(x, y), addedges(y, x);
  }
  dfs(1, 1), inv[0] = fac[0] = 1, f[0] = 0;
  for (int i = 1; i <= n; i++)
    fac[i] = fac[i - 1] * i % P;
  for (int i = 1; i <= n; i++)
    inv[i] = fsp(fac[i], P - 2);
  for (int i = 0; i <= n; i++)
    f[i] = f[i] * fac[i] % P;
  for (int i = 0; i <= n; i++)
    g[i] = inv[i];
  for (m = n; (1 << len) <= n + n; ++len)
    ;
  n = 1 << len, Inv = fsp(n, P - 2), reverse(f, f + n);
  for (int i = 1; i < n; i++)
    r[i] = (r[i >> 1] >> 1) | ((i & 1) << (len - 1));
  NTT(f, 0), NTT(g, 0);
  for (int i = 0; i < n; i++)
    f[i] = f[i] * g[i] % P;
  NTT(f, 1), reverse(f, f + n);
  for (int i = 1; i <= m; i++)
    printf("%lld\n", (m * C(m, i) - f[i] * inv[i] % P + P) % P);
  return 0;
}