Problem p03991 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define LL long long
#define RG register
#define il inline
#define N 400010
#define mod 924844033
using namespace std;
struct ed {
  int nxt, to;
} e[N * 2];
int head[N], tot, n, m, R[N], A[N], B[N], fac[N], _fac[N], sz[N];
void link(int u, int v) {
  e[tot].nxt = head[u];
  e[tot].to = v;
  head[u] = tot++;
}
void lnk(int u, int v) { link(u, v), link(v, u); }
void dfs(int u, int faa) {
  A[n]++;
  sz[u] = 1;
  for (int i = head[u]; i != -1; i = e[i].nxt) {
    int v = e[i].to;
    if (v == faa)
      continue;
    dfs(v, u);
    sz[u] += sz[v];
    A[sz[v]]--;
    if (A[sz[v]] < 0)
      A[sz[v]] += mod;
  }
  A[n - sz[u]]--;
  if (A[n - sz[u]] < 0)
    A[n - sz[u]] += mod;
}
int qp(int a, int b) {
  if (!b)
    return 1;
  if (a == 1)
    return a;
  int temp = qp(a, (b >> 1));
  temp = 1ll * temp * temp % mod;
  if (b & 1)
    temp = 1ll * temp * a % mod;
  return temp;
}
void NTT(int *a, int f) {
  for (int i = 0; i < n; ++i)
    if (i < R[i])
      swap(a[i], a[R[i]]);
  for (int i = 1; i < n; i <<= 1) {
    int gn = qp(5, (mod - 1) / (i << 1));
    for (int j = 0; j < n; j += (i << 1)) {
      int g = 1;
      for (int k = 0; k < i; ++k, g = 1ll * g * gn % mod) {
        int x = a[j + k], y = 1ll * g * a[j + k + i] % mod;
        a[j + k] = (x + y) % mod;
        a[j + k + i] = (x - y + mod) % mod;
      }
    }
  }
  if (f == -1) {
    reverse(a + 1, a + n);
    int _n = qp(n, mod - 2);
    for (int i = 0; i < n; ++i)
      a[i] = 1ll * a[i] * _n % mod;
  }
}
int main() {
  memset(head, -1, sizeof(head));
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v), lnk(u, v);
  }
  dfs(1, 1);
  fac[1] = 1;
  fac[0] = 1;
  for (int i = 2; i <= n; ++i)
    fac[i] = 1ll * fac[i - 1] * i % mod, A[i] = 1ll * A[i] * fac[i] % mod;
  _fac[n] = qp(fac[n], mod - 2);
  for (int i = n; i; --i)
    _fac[i - 1] = 1ll * _fac[i] * i % mod;
  for (int i = 1; i <= n; ++i)
    B[i] = _fac[n - i];
  m = n;
  int L = 0;
  for (n = 1; n <= (m << 1); n <<= 1)
    L++;
  for (int i = 0; i < n; ++i)
    R[i] = (R[i >> 1] >> 1) | ((i & 1) << (L - 1));
  NTT(A, 1), NTT(B, 1);
  for (int i = 0; i < n; ++i)
    A[i] = 1ll * A[i] * B[i] % mod;
  NTT(A, -1);
  for (int i = 1; i <= m; ++i)
    printf("%d\n", 1ll * A[m + i] * _fac[i] % mod);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define LL long long
#define RG register
#define il inline
#define N 400010
#define mod 924844033
using namespace std;
struct ed {
  int nxt, to;
} e[N * 2];
int head[N], tot, n, m, R[N * 2], A[N * 2], B[N * 2], fac[N * 2], _fac[N * 2],
    sz[N];
void link(int u, int v) {
  e[tot].nxt = head[u];
  e[tot].to = v;
  head[u] = tot++;
}
void lnk(int u, int v) { link(u, v), link(v, u); }
void dfs(int u, int faa) {
  A[n]++;
  sz[u] = 1;
  for (int i = head[u]; i != -1; i = e[i].nxt) {
    int v = e[i].to;
    if (v == faa)
      continue;
    dfs(v, u);
    sz[u] += sz[v];
    A[sz[v]]--;
    if (A[sz[v]] < 0)
      A[sz[v]] += mod;
  }
  A[n - sz[u]]--;
  if (A[n - sz[u]] < 0)
    A[n - sz[u]] += mod;
}
int qp(int a, int b) {
  if (!b)
    return 1;
  if (a == 1)
    return a;
  int temp = qp(a, (b >> 1));
  temp = 1ll * temp * temp % mod;
  if (b & 1)
    temp = 1ll * temp * a % mod;
  return temp;
}
void NTT(int *a, int f) {
  for (int i = 0; i < n; ++i)
    if (i < R[i])
      swap(a[i], a[R[i]]);
  for (int i = 1; i < n; i <<= 1) {
    int gn = qp(5, (mod - 1) / (i << 1));
    for (int j = 0; j < n; j += (i << 1)) {
      int g = 1;
      for (int k = 0; k < i; ++k, g = 1ll * g * gn % mod) {
        int x = a[j + k], y = 1ll * g * a[j + k + i] % mod;
        a[j + k] = (x + y) % mod;
        a[j + k + i] = (x - y + mod) % mod;
      }
    }
  }
  if (f == -1) {
    reverse(a + 1, a + n);
    int _n = qp(n, mod - 2);
    for (int i = 0; i < n; ++i)
      a[i] = 1ll * a[i] * _n % mod;
  }
}
int main() {
  memset(head, -1, sizeof(head));
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v), lnk(u, v);
  }
  dfs(1, 1);
  fac[1] = 1;
  fac[0] = 1;
  for (int i = 2; i <= n; ++i)
    fac[i] = 1ll * fac[i - 1] * i % mod, A[i] = 1ll * A[i] * fac[i] % mod;
  _fac[n] = qp(fac[n], mod - 2);
  for (int i = n; i; --i)
    _fac[i - 1] = 1ll * _fac[i] * i % mod;
  for (int i = 1; i <= n; ++i)
    B[i] = _fac[n - i];
  m = n;
  int L = 0;
  for (n = 1; n <= (m << 1); n <<= 1)
    L++;
  for (int i = 0; i < n; ++i)
    R[i] = (R[i >> 1] >> 1) | ((i & 1) << (L - 1));
  NTT(A, 1), NTT(B, 1);
  for (int i = 0; i < n; ++i)
    A[i] = 1ll * A[i] * B[i] % mod;
  NTT(A, -1);
  for (int i = 1; i <= m; ++i)
    printf("%d\n", 1ll * A[m + i] * _fac[i] % mod);
  return 0;
}