Problem p03991 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

#define For(i, j, k) for (int i = j; i <= k; i++)
#define Forr(i, j, k) for (int i = j; i >= k; i--)
#define pb push_back

using namespace std;

const int N = 510010;
const int Mod = 924844033;
const int r = 5;

typedef long long LL;

LL Pow(LL x, LL e) {
  LL ret = 1;
  while (e) {
    if (e & 1)
      ret = ret * x % Mod;
    x = x * x % Mod;
    e >>= 1;
  }
  return ret;
}

int rev[N];

void DFT(LL *A, int n, bool inv) {
  For(i, 0, n - 1) if (i < rev[i]) swap(A[i], A[rev[i]]);
  for (int i = 2; i <= n; i <<= 1) {
    LL w = Pow(r, (Mod - 1) / i);
    if (inv)
      w = Pow(w, Mod - 2);
    for (int j = 0; j < n; j += i) {
      LL cur = 1;
      for (int k = 0; k < (i >> 1); ++k) {
        LL x = A[j + k], y = A[j + k + (i >> 1)] * cur % Mod;
        A[j + k] = (x + y) % Mod, A[j + k + (i >> 1)] = (x - y + Mod) % Mod;
        cur = cur * w % Mod;
      }
    }
  }
}

void NTT(LL *A, LL *B, int m) {
  int n = 1;
  while (n <= m + 2)
    n <<= 1;
  For(i, 1, n - 1) rev[i] = (rev[i >> 1] >> 1) | (i & 1 ? n >> 1 : 0);
  DFT(A, n, 0), DFT(B, n, 0);
  For(i, 0, n - 1) A[i] = A[i] * B[i] % Mod;
  DFT(A, n, 1);
  LL inv = Pow(n, Mod - 2);
  For(i, 0, n - 1) A[i] = A[i] * inv % Mod;
}

LL coe[N], F[N], fac[N], rfac[N];
int n, sz[N];
vector<int> G[N];

void DFS(int o, int f) {
  sz[o] = 1;
  for (int v : G[o]) {
    if (v == f)
      continue;
    DFS(v, o);
    sz[o] += sz[v];
    coe[sz[v]]++;
  }
  if (n > sz[o])
    coe[n - sz[o]]++;
}

LL C(int a, int b) { return fac[a] * rfac[b] % Mod * rfac[a - b] % Mod; }

int main() {
  scanf("%d", &n);
  For(i, 2, n) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].pb(v), G[v].pb(u);
  }

  fac[0] = 1;
  For(i, 1, n) fac[i] = fac[i - 1] * i % Mod;
  rfac[n] = Pow(fac[n], Mod - 2);
  Forr(i, n - 1, 0) rfac[i] = rfac[i + 1] * (i + 1) % Mod;
  DFS(1, 0);

  For(i, 1, n) coe[i] = coe[i] * fac[i] % Mod;
  For(i, 0, n) F[i] = rfac[n - i];

  NTT(coe, F, 2 * n);

  For(i, 1, n) printf(
      "%lld\n",
      (1ll * n * C(n, i) % Mod - coe[n + i] * rfac[i] % Mod + Mod) % Mod);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

#define For(i, j, k) for (int i = j; i <= k; i++)
#define Forr(i, j, k) for (int i = j; i >= k; i--)
#define pb push_back

using namespace std;

const int N = 1010010;
const int Mod = 924844033;
const int r = 5;

typedef long long LL;

LL Pow(LL x, LL e) {
  LL ret = 1;
  while (e) {
    if (e & 1)
      ret = ret * x % Mod;
    x = x * x % Mod;
    e >>= 1;
  }
  return ret;
}

int rev[N];

void DFT(LL *A, int n, bool inv) {
  For(i, 0, n - 1) if (i < rev[i]) swap(A[i], A[rev[i]]);
  for (int i = 2; i <= n; i <<= 1) {
    LL w = Pow(r, (Mod - 1) / i);
    if (inv)
      w = Pow(w, Mod - 2);
    for (int j = 0; j < n; j += i) {
      LL cur = 1;
      for (int k = 0; k < (i >> 1); ++k) {
        LL x = A[j + k], y = A[j + k + (i >> 1)] * cur % Mod;
        A[j + k] = (x + y) % Mod, A[j + k + (i >> 1)] = (x - y + Mod) % Mod;
        cur = cur * w % Mod;
      }
    }
  }
}

void NTT(LL *A, LL *B, int m) {
  int n = 1;
  while (n <= m + 2)
    n <<= 1;
  For(i, 1, n - 1) rev[i] = (rev[i >> 1] >> 1) | (i & 1 ? n >> 1 : 0);
  DFT(A, n, 0), DFT(B, n, 0);
  For(i, 0, n - 1) A[i] = A[i] * B[i] % Mod;
  DFT(A, n, 1);
  LL inv = Pow(n, Mod - 2);
  For(i, 0, n - 1) A[i] = A[i] * inv % Mod;
}

LL coe[N], F[N], fac[N], rfac[N];
int n, sz[N];
vector<int> G[N];

void DFS(int o, int f) {
  sz[o] = 1;
  for (int v : G[o]) {
    if (v == f)
      continue;
    DFS(v, o);
    sz[o] += sz[v];
    coe[sz[v]]++;
  }
  if (n > sz[o])
    coe[n - sz[o]]++;
}

LL C(int a, int b) { return fac[a] * rfac[b] % Mod * rfac[a - b] % Mod; }

int main() {
  scanf("%d", &n);
  For(i, 2, n) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].pb(v), G[v].pb(u);
  }

  fac[0] = 1;
  For(i, 1, n) fac[i] = fac[i - 1] * i % Mod;
  rfac[n] = Pow(fac[n], Mod - 2);
  Forr(i, n - 1, 0) rfac[i] = rfac[i + 1] * (i + 1) % Mod;
  DFS(1, 0);

  For(i, 1, n) coe[i] = coe[i] * fac[i] % Mod;
  For(i, 0, n) F[i] = rfac[n - i];

  NTT(coe, F, 2 * n);

  For(i, 1, n) printf(
      "%lld\n",
      (1ll * n * C(n, i) % Mod - coe[n + i] * rfac[i] % Mod + Mod) % Mod);
  return 0;
}