Problem p03991 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, x, y) for (register int i = x; i <= y; ++i)
#define repd(i, x, y) for (register int i = x; i >= y; --i)
#define repl(i, x) for (register int i = fi[x]; i; i = l[i].next)
using namespace std;
typedef long long ll;
const int maxn = 500010, P = 924844033, g = 5;
struct line {
  int y, next;
} l[maxn];
int n, siz[maxn], cnt[maxn];
int lcnt, fi[maxn];
int fac[maxn], Inv[maxn];
int N, rev[maxn], A[maxn], B[maxn], C[maxn];
int read() {
  int num = 0, flag = 1;
  char c = getchar();
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-')
      flag = 0;
  for (; c >= '0' && c <= '9'; c = getchar())
    num = (num << 3) + (num << 1) + c - 48;
  return flag ? num : -num;
}
inline int Add(int x, int y) { return x + y < P ? x + y : x + y - P; }
inline int Mul(int x, int y) { return 1LL * x * y % P; }
inline int Del(int x, int y) { return x >= y ? x - y : x - y + P; }
void make_line(int x, int y) {
  l[++lcnt].y = y;
  l[lcnt].next = fi[x];
  fi[x] = lcnt;
}
int power(int x, int y, int ans = 1) {
  for (; y; y >>= 1, x = Mul(x, x))
    if (y & 1)
      ans = Mul(ans, x);
  return ans;
}

void init() {
  n = read();
  rep(i, 1, n - 1) {
    int x = read(), y = read();
    make_line(x, y);
    make_line(y, x);
  }
}

void get_siz(int x, int f) {
  siz[x] = 1;
  repl(i, x) {
    int v = l[i].y;
    if (v == f)
      continue;
    get_siz(v, x);
    siz[x] += siz[v];
  }
}

void get_cnt(int x, int f) {
  repl(i, x) {
    int v = l[i].y;
    if (v == f)
      continue;
    ++cnt[siz[v]];
    get_cnt(v, x);
  }
  if (x != 1)
    ++cnt[n - siz[x]];
}

void NTT(int a[], int N, int opt) {
  int L = log2(N);
  rep(i, 0, N - 1) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (L - 1));
  rep(i, 0, N - 1) if (i < rev[i]) swap(a[i], a[rev[i]]);
  for (int i = 1; i < N; i <<= 1) {
    int step = i << 1;
    int wn = power(g, (P - 1) / step);
    if (opt == -1)
      wn = power(wn, P - 2);
    for (int j = 0; j < N; j += step) {
      int w = 1;
      for (int k = 0; k < i; ++k) {
        int x = a[j + k], y = Mul(w, a[j + k + i]);
        a[j + k] = Add(x, y);
        a[j + k + i] = Del(x, y);
        w = Mul(w, wn);
      }
    }
  }
  if (opt == -1) {
    int Inv = power(N, P - 2);
    rep(i, 0, N - 1) a[i] = Mul(a[i], Inv);
  }
}

void first() {
  get_siz(1, 0);
  get_cnt(1, 0);
  fac[0] = 1;
  rep(i, 1, n) fac[i] = Mul(fac[i - 1], i);
  Inv[n] = power(fac[n], P - 2);
  repd(i, n - 1, 1) Inv[i] = Mul(Inv[i + 1], i + 1);
  rep(i, 1, n - 1) A[i] = Mul(P - cnt[i], fac[i]);
  A[n] = Mul(n, fac[n]);
  rep(i, 1, n) B[i] = Inv[n - i + 1];
  B[n + 1] = 1;
  //	rep(i, 1, n) printf("%d ", cnt[i]); puts("");
}

void work() {
  for (N = 1; N <= n * 2; N <<= 1)
    ;
  //	rep(i, 0, N-1) printf("%d ", A[i]); puts("");
  //	rep(i, 0, N-1) printf("%d ", B[i]); puts("");
  NTT(A, N, 1);
  NTT(B, N, 1);
  rep(i, 0, N - 1) C[i] = Mul(A[i], B[i]);
  NTT(C, N, -1);
  //	rep(i, 0, N-1) printf("%d ", C[i]); puts("");
  rep(i, 1, n) printf("%d\n", Mul(C[n + i + 1], Inv[i]));
}

int main() {
  // freopen(".in", "r", stdin);
  // freopen(".out", "w", stdout);
  init();
  first();
  work();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, x, y) for (register int i = x; i <= y; ++i)
#define repd(i, x, y) for (register int i = x; i >= y; --i)
#define repl(i, x) for (register int i = fi[x]; i; i = l[i].next)
using namespace std;
typedef long long ll;
const int maxn = 1000010, P = 924844033, g = 5;
struct line {
  int y, next;
} l[maxn];
int n, siz[maxn], cnt[maxn];
int lcnt, fi[maxn];
int fac[maxn], Inv[maxn];
int N, rev[maxn], A[maxn], B[maxn], C[maxn];
int read() {
  int num = 0, flag = 1;
  char c = getchar();
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-')
      flag = 0;
  for (; c >= '0' && c <= '9'; c = getchar())
    num = (num << 3) + (num << 1) + c - 48;
  return flag ? num : -num;
}
inline int Add(int x, int y) { return x + y < P ? x + y : x + y - P; }
inline int Mul(int x, int y) { return 1LL * x * y % P; }
inline int Del(int x, int y) { return x >= y ? x - y : x - y + P; }
void make_line(int x, int y) {
  l[++lcnt].y = y;
  l[lcnt].next = fi[x];
  fi[x] = lcnt;
}
int power(int x, int y, int ans = 1) {
  for (; y; y >>= 1, x = Mul(x, x))
    if (y & 1)
      ans = Mul(ans, x);
  return ans;
}

void init() {
  n = read();
  rep(i, 1, n - 1) {
    int x = read(), y = read();
    make_line(x, y);
    make_line(y, x);
  }
}

void get_siz(int x, int f) {
  siz[x] = 1;
  repl(i, x) {
    int v = l[i].y;
    if (v == f)
      continue;
    get_siz(v, x);
    siz[x] += siz[v];
  }
}

void get_cnt(int x, int f) {
  repl(i, x) {
    int v = l[i].y;
    if (v == f)
      continue;
    ++cnt[siz[v]];
    get_cnt(v, x);
  }
  if (x != 1)
    ++cnt[n - siz[x]];
}

void NTT(int a[], int N, int opt) {
  int L = log2(N);
  rep(i, 0, N - 1) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (L - 1));
  rep(i, 0, N - 1) if (i < rev[i]) swap(a[i], a[rev[i]]);
  for (int i = 1; i < N; i <<= 1) {
    int step = i << 1;
    int wn = power(g, (P - 1) / step);
    if (opt == -1)
      wn = power(wn, P - 2);
    for (int j = 0; j < N; j += step) {
      int w = 1;
      for (int k = 0; k < i; ++k) {
        int x = a[j + k], y = Mul(w, a[j + k + i]);
        a[j + k] = Add(x, y);
        a[j + k + i] = Del(x, y);
        w = Mul(w, wn);
      }
    }
  }
  if (opt == -1) {
    int Inv = power(N, P - 2);
    rep(i, 0, N - 1) a[i] = Mul(a[i], Inv);
  }
}

void first() {
  get_siz(1, 0);
  get_cnt(1, 0);
  fac[0] = 1;
  rep(i, 1, n) fac[i] = Mul(fac[i - 1], i);
  Inv[n] = power(fac[n], P - 2);
  repd(i, n - 1, 1) Inv[i] = Mul(Inv[i + 1], i + 1);
  rep(i, 1, n - 1) A[i] = Mul(P - cnt[i], fac[i]);
  A[n] = Mul(n, fac[n]);
  rep(i, 1, n) B[i] = Inv[n - i + 1];
  B[n + 1] = 1;
  //	rep(i, 1, n) printf("%d ", cnt[i]); puts("");
}

void work() {
  for (N = 1; N <= n * 2; N <<= 1)
    ;
  //	rep(i, 0, N-1) printf("%d ", A[i]); puts("");
  //	rep(i, 0, N-1) printf("%d ", B[i]); puts("");
  NTT(A, N, 1);
  NTT(B, N, 1);
  rep(i, 0, N - 1) C[i] = Mul(A[i], B[i]);
  NTT(C, N, -1);
  //	rep(i, 0, N-1) printf("%d ", C[i]); puts("");
  rep(i, 1, n) printf("%d\n", Mul(C[n + i + 1], Inv[i]));
}

int main() {
  // freopen(".in", "r", stdin);
  // freopen(".out", "w", stdout);
  init();
  first();
  work();
  return 0;
}