Problem p03991 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define LL long long
#define uLL unsigned long long
#define db double

using namespace std;
const int N = 2e3 + 10, M = (1 << 19) + 10, mod = 924844033;
int rd() {
  int x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * w;
}
int to[N << 1], nt[N << 1], hd[N], tot = 1;
void adde(int x, int y) {
  ++tot, to[tot] = y, nt[tot] = hd[x], hd[x] = tot;
  ++tot, to[tot] = x, nt[tot] = hd[y], hd[y] = tot;
}
int sz[N];
void dfs(int x, int ffa) {
  sz[x] = 1;
  for (int i = hd[x]; i; i = nt[i]) {
    int y = to[i];
    if (y == ffa)
      continue;
    dfs(y, x), sz[x] += sz[y];
  }
}
void ad(int &x, int y) { x += y, x -= x >= mod ? mod : 0; }
int fpow(int a, LL b, int mod) {
  int an = 1;
  while (b) {
    if (b & 1)
      an = 1ll * an * a % mod;
    a = 1ll * a * a % mod, b >>= 1;
  }
  return an;
}
int ginv(int a, int mod) { return fpow(a, mod - 2, mod); }
int rdr[M], W[20], iW[20];
void ntt(int *a, int n, bool op) {
  int l = 0, x, y;
  while (1 << l < n)
    ++l;
  for (int i = 0; i < n; ++i) {
    rdr[i] = (rdr[i >> 1] >> 1) | ((i & 1) << (l - 1));
    if (i < rdr[i])
      swap(a[i], a[rdr[i]]);
  }
  for (int i = 1, p = 0; i < n; i <<= 1, ++p) {
    int ww = op ? W[p] : iW[p];
    for (int j = 0; j < n; j += i << 1)
      for (int k = 0, w = 1; k < i; ++k, w = 1ll * w * ww % mod)
        x = a[j + k], y = 1ll * a[j + k + i] * w % mod,
        a[j + k] = (x + y) % mod, a[j + k + i] = (x - y + mod) % mod;
  }
  if (!op)
    for (int i = 0, w = ginv(n, mod); i < n; ++i)
      a[i] = 1ll * a[i] * w % mod;
}
int p1[M], p2[M];
void MUL(int *a, int n, int *b, int m) {
  int len = 1;
  while (len <= n + m)
    len <<= 1;
  memcpy(p1, a, sizeof(int) * n), memcpy(p2, b, sizeof(int) * m);
  ntt(p1, len, 1), ntt(p2, len, 1);
  for (int i = 0; i < len; ++i)
    p1[i] = 1ll * p1[i] * p2[i] % mod;
  ntt(p1, len, 0);
  memcpy(a, p1, sizeof(int) * n);
  memset(p1, 0, sizeof(int) * len), memset(p2, 0, sizeof(int) * len);
}
int n, k, cn[N], fac[N], iac[N], an[N], aa[N], bb[N];
int C(int a, int b) {
  return b < 0 || a < b ? 0 : 1ll * fac[a] * iac[b] % mod * iac[a - b] % mod;
}

int main() {
  for (int i = 1, p = 0; p < 20; i <<= 1, ++p)
    W[p] = fpow(5, (mod - 1) / (i << 1), mod), iW[p] = ginv(W[p], mod);
  fac[0] = 1;
  for (int i = 1; i <= N - 10; ++i)
    fac[i] = 1ll * fac[i - 1] * i % mod;
  iac[N - 10] = ginv(fac[N - 10], mod);
  for (int i = N - 10; i; --i)
    iac[i - 1] = 1ll * iac[i] * i % mod;
  n = rd();
  for (int i = 1; i < n; ++i)
    adde(rd(), rd());
  dfs(1, 0);
  for (int i = 2; i <= n; ++i)
    ++cn[sz[i]];
  for (int i = 1; i <= n; ++i)
    an[i] = 1ll * C(n, i) * n % mod;
  for (int i = 0; i <= n; ++i)
    aa[n - i] = 1ll * cn[i] * fac[i] % mod;
  for (int i = 0; i <= n; ++i)
    bb[i] = iac[i];
  MUL(aa, n + 1, bb, n + 1);
  for (int i = 1; i <= n; ++i)
    ad(an[i], mod - 1ll * aa[n - i] * iac[i] % mod);
  for (int i = 0; i <= n; ++i)
    aa[n - i] = 1ll * cn[n - i] * fac[i] % mod;
  for (int i = 0; i <= n; ++i)
    bb[i] = iac[i];
  MUL(aa, n + 1, bb, n + 1);
  for (int i = 1; i <= n; ++i)
    ad(an[i], mod - 1ll * aa[n - i] * iac[i] % mod);
  for (int i = 1; i <= n; ++i)
    printf("%d\n", an[i]);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define LL long long
#define uLL unsigned long long
#define db double

using namespace std;
const int N = 2e5 + 10, M = (1 << 19) + 10, mod = 924844033;
int rd() {
  int x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * w;
}
int to[N << 1], nt[N << 1], hd[N], tot = 1;
void adde(int x, int y) {
  ++tot, to[tot] = y, nt[tot] = hd[x], hd[x] = tot;
  ++tot, to[tot] = x, nt[tot] = hd[y], hd[y] = tot;
}
int sz[N];
void dfs(int x, int ffa) {
  sz[x] = 1;
  for (int i = hd[x]; i; i = nt[i]) {
    int y = to[i];
    if (y == ffa)
      continue;
    dfs(y, x), sz[x] += sz[y];
  }
}
void ad(int &x, int y) { x += y, x -= x >= mod ? mod : 0; }
int fpow(int a, LL b, int mod) {
  int an = 1;
  while (b) {
    if (b & 1)
      an = 1ll * an * a % mod;
    a = 1ll * a * a % mod, b >>= 1;
  }
  return an;
}
int ginv(int a, int mod) { return fpow(a, mod - 2, mod); }
int rdr[M], W[20], iW[20];
void ntt(int *a, int n, bool op) {
  int l = 0, x, y;
  while (1 << l < n)
    ++l;
  for (int i = 0; i < n; ++i) {
    rdr[i] = (rdr[i >> 1] >> 1) | ((i & 1) << (l - 1));
    if (i < rdr[i])
      swap(a[i], a[rdr[i]]);
  }
  for (int i = 1, p = 0; i < n; i <<= 1, ++p) {
    int ww = op ? W[p] : iW[p];
    for (int j = 0; j < n; j += i << 1)
      for (int k = 0, w = 1; k < i; ++k, w = 1ll * w * ww % mod)
        x = a[j + k], y = 1ll * a[j + k + i] * w % mod,
        a[j + k] = (x + y) % mod, a[j + k + i] = (x - y + mod) % mod;
  }
  if (!op)
    for (int i = 0, w = ginv(n, mod); i < n; ++i)
      a[i] = 1ll * a[i] * w % mod;
}
int p1[M], p2[M];
void MUL(int *a, int n, int *b, int m) {
  int len = 1;
  while (len <= n + m)
    len <<= 1;
  memcpy(p1, a, sizeof(int) * n), memcpy(p2, b, sizeof(int) * m);
  ntt(p1, len, 1), ntt(p2, len, 1);
  for (int i = 0; i < len; ++i)
    p1[i] = 1ll * p1[i] * p2[i] % mod;
  ntt(p1, len, 0);
  memcpy(a, p1, sizeof(int) * n);
  memset(p1, 0, sizeof(int) * len), memset(p2, 0, sizeof(int) * len);
}
int n, k, cn[N], fac[N], iac[N], an[N], aa[N], bb[N];
int C(int a, int b) {
  return b < 0 || a < b ? 0 : 1ll * fac[a] * iac[b] % mod * iac[a - b] % mod;
}

int main() {
  for (int i = 1, p = 0; p < 20; i <<= 1, ++p)
    W[p] = fpow(5, (mod - 1) / (i << 1), mod), iW[p] = ginv(W[p], mod);
  fac[0] = 1;
  for (int i = 1; i <= N - 10; ++i)
    fac[i] = 1ll * fac[i - 1] * i % mod;
  iac[N - 10] = ginv(fac[N - 10], mod);
  for (int i = N - 10; i; --i)
    iac[i - 1] = 1ll * iac[i] * i % mod;
  n = rd();
  for (int i = 1; i < n; ++i)
    adde(rd(), rd());
  dfs(1, 0);
  for (int i = 2; i <= n; ++i)
    ++cn[sz[i]];
  for (int i = 1; i <= n; ++i)
    an[i] = 1ll * C(n, i) * n % mod;
  for (int i = 0; i <= n; ++i)
    aa[n - i] = 1ll * cn[i] * fac[i] % mod;
  for (int i = 0; i <= n; ++i)
    bb[i] = iac[i];
  MUL(aa, n + 1, bb, n + 1);
  for (int i = 1; i <= n; ++i)
    ad(an[i], mod - 1ll * aa[n - i] * iac[i] % mod);
  for (int i = 0; i <= n; ++i)
    aa[n - i] = 1ll * cn[n - i] * fac[i] % mod;
  for (int i = 0; i <= n; ++i)
    bb[i] = iac[i];
  MUL(aa, n + 1, bb, n + 1);
  for (int i = 1; i <= n; ++i)
    ad(an[i], mod - 1ll * aa[n - i] * iac[i] % mod);
  for (int i = 1; i <= n; ++i)
    printf("%d\n", an[i]);
  return 0;
}