Problem p03991 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 524250;
int lim = 1, M = 924844033, a[N], r[N], fac[N], inv[N], b[N], tot, h[N], sz[N],
    g = 5, gi = 554906420, n, i, x, y, l;
struct node {
  int to, ne;
} e[N];
inline int mul(int x, int y) { return 1ll * x * y % M; }
inline int inc(int x, int y) {
  x += y;
  if (x >= M)
    x -= M;
  return x;
}
inline int dec(int x, int y) {
  x -= y;
  if (x < 0)
    x += M;
  return x;
}
void add(int x, int y) { e[++tot] = {y, h[x]}, h[x] = tot; }
int pw(int x, int y) {
  int z = 1;
  for (; y; y >>= 1, x = 1ll * x * x % M)
    if (y & 1)
      z = 1ll * z * x % M;
  return z;
}
int Inv(int x) { return pw(x, M - 2); }
void dfs(int u, int fa) {
  sz[u] = 1;
  for (int i = h[u], v; i; i = e[i].ne)
    if ((v = e[i].to) != fa)
      dfs(v, u), sz[u] += sz[v], a[sz[v]]++;
  a[n - sz[u]]++;
}
void ntt(int *a, int op) {
  for (int i = 0; i < lim; i++)
    if (i < r[i])
      swap(a[i], a[r[i]]);
  for (int mid = 1, pp = M - 1 >> 1; mid < lim; mid <<= 1, pp >>= 1)
    for (int R = mid << 1, j = 0, wn = pw(op == 1 ? g : gi, pp); j < lim;
         j += R)
      for (int k = 0, w = 1; k < mid; k++, w = mul(w, wn)) {
        int x = a[j | k], y = mul(w, a[j | k | mid]);
        a[j | k] = inc(x, y);
        a[j | k | mid] = dec(x, y);
      }
  if (op == -1) {
    int inv = Inv(lim);
    for (int i = 0; i < lim; i++)
      a[i] = mul(a[i], inv);
  }
}
int main() {
  scanf("%d", &n);
  for (i = 1; i < n; i++)
    scanf("%d%d", &x, &y), add(x, y), add(y, x);
  dfs(1, 0);
  fac[0] = 1, a[0] = 0;
  for (i = 1; i <= n; i++)
    fac[i] = 1ll * fac[i - 1] * i % M, a[i] = 1ll * a[i] * fac[i] % M;
  b[0] = inv[n] = Inv(fac[n]);
  for (i = n - 1; ~i; i--)
    inv[i] = 1ll * inv[i + 1] * (i + 1) % M, b[n - i] = inv[i];
  for (; lim <= n + n; lim <<= 1, l++)
    ;
  for (i = 0; i < lim; i++)
    r[i] = (r[i >> 1] >> 1) | ((i & 1) << (l - 1));
  ntt(a, 1), ntt(b, 1);
  for (i = 0; i < lim; i++)
    a[i] = 1ll * a[i] * b[i] % M;
  ntt(a, -1);
  for (i = 1; i <= n; i++)
    printf("%lld\n", (1ll * fac[n] * inv[i] % M * inv[n - i] % M * n % M -
                      1ll * inv[i] * a[n + i] % M + M) %
                         M);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = (1 << 20) + 5;
int lim = 1, M = 924844033, a[N], r[N], fac[N], inv[N], b[N], tot, h[N], sz[N],
    g = 5, gi = 554906420, n, i, x, y, l;
struct node {
  int to, ne;
} e[N];
inline int mul(int x, int y) { return 1ll * x * y % M; }
inline int inc(int x, int y) {
  x += y;
  if (x >= M)
    x -= M;
  return x;
}
inline int dec(int x, int y) {
  x -= y;
  if (x < 0)
    x += M;
  return x;
}
void add(int x, int y) { e[++tot] = {y, h[x]}, h[x] = tot; }
int pw(int x, int y) {
  int z = 1;
  for (; y; y >>= 1, x = 1ll * x * x % M)
    if (y & 1)
      z = 1ll * z * x % M;
  return z;
}
int Inv(int x) { return pw(x, M - 2); }
void dfs(int u, int fa) {
  sz[u] = 1;
  for (int i = h[u], v; i; i = e[i].ne)
    if ((v = e[i].to) != fa)
      dfs(v, u), sz[u] += sz[v], a[sz[v]]++;
  a[n - sz[u]]++;
}
void ntt(int *a, int op) {
  for (int i = 0; i < lim; i++)
    if (i < r[i])
      swap(a[i], a[r[i]]);
  for (int mid = 1, pp = M - 1 >> 1; mid < lim; mid <<= 1, pp >>= 1)
    for (int R = mid << 1, j = 0, wn = pw(op == 1 ? g : gi, pp); j < lim;
         j += R)
      for (int k = 0, w = 1; k < mid; k++, w = mul(w, wn)) {
        int x = a[j | k], y = mul(w, a[j | k | mid]);
        a[j | k] = inc(x, y);
        a[j | k | mid] = dec(x, y);
      }
  if (op == -1) {
    int inv = Inv(lim);
    for (int i = 0; i < lim; i++)
      a[i] = mul(a[i], inv);
  }
}
int main() {
  scanf("%d", &n);
  for (i = 1; i < n; i++)
    scanf("%d%d", &x, &y), add(x, y), add(y, x);
  dfs(1, 0);
  fac[0] = 1, a[0] = 0;
  for (i = 1; i <= n; i++)
    fac[i] = 1ll * fac[i - 1] * i % M, a[i] = 1ll * a[i] * fac[i] % M;
  b[0] = inv[n] = Inv(fac[n]);
  for (i = n - 1; ~i; i--)
    inv[i] = 1ll * inv[i + 1] * (i + 1) % M, b[n - i] = inv[i];
  for (; lim <= n + n; lim <<= 1, l++)
    ;
  for (i = 0; i < lim; i++)
    r[i] = (r[i >> 1] >> 1) | ((i & 1) << (l - 1));
  ntt(a, 1), ntt(b, 1);
  for (i = 0; i < lim; i++)
    a[i] = 1ll * a[i] * b[i] % M;
  ntt(a, -1);
  for (i = 1; i <= n; i++)
    printf("%lld\n", (1ll * fac[n] * inv[i] % M * inv[n - i] % M * n % M -
                      1ll * inv[i] * a[n + i] % M + M) %
                         M);
}