Problem p03991 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define o 1000005
#define re register int
#define ll long long
#define g0(a) memset(a, 0, sizeof(a))
#define gc(a, b) memcpy(a, b, sizeof(a))
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define REP(i, a, b) for (int i = a; i >= b; i--)
#define pa pair<int, int>
#define mpp make_pair
#define s1 first
#define s2 second
#define go(x) for (ll i = h[x]; i; i = w[i].next)
using namespace std;
inline int read() {
  register int data = 0, w = 1;
  char ch = 0;
  while (ch != '-' && (ch < '0' || ch > '9'))
    ch = getchar();
  if (ch == '-')
    w = -1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    data = (data << 1) + (data << 3) + (ch ^ 48), ch = getchar();
  return data * w;
}
int h[o], cnt;
struct node {
  int to, next;
} w[o];
void add(int x, int y) {
  ++cnt;
  w[cnt].to = y;
  w[cnt].next = h[x];
  h[x] = cnt;
}
int n, rev[o];
int Make(int n) {
  int t = ceil(log2(n + 1));
  FOR(i, 0, (1 << t) - 1) rev[i] = (rev[i >> 1] >> 1 | (i & 1) << t - 1);
  return t;
}
const int mod = 924844033924844033;
int KSM(int x, int k) {
  int tmp = 1, y = x;
  for (int i = k; i; i >>= 1, y = 1ll * y * y % mod)
    if (i & 1)
      tmp = 1ll * tmp * y % mod;
  return tmp;
}
void Add(int &x, int y) {
  x += y - mod;
  x += x >> 31 & mod;
}
void dec(int &x, int y) {
  x -= y;
  x += x >> 31 & mod;
}
void fix(int &x) { x += x >> 31 & mod; }
void NTT(int a[], int n, int d) {
  FOR(i, 0, (1 << n) - 1) if (i < rev[i]) swap(a[i], a[rev[i]]);
  for (int m = 0; m < n; ++m) {
    int w = KSM(5, mod - 1 + (mod - 1) / (2 << m) * d);
    for (int i = 0; i < 1 << n; i += 2 << m)
      for (int k = i, x = 1; k < i + (1 << m); ++k, x = 1ll * x * w % mod) {
        int t0 = a[k], t1 = 1ll * x * a[k + (1 << m)] % mod;
        Add(a[k], t1);
        fix(a[k + (1 << m)] = t0 - t1);
      }
  }
  if (d == -1) {
    int x = KSM(1 << n, mod - 2);
    FOR(i, 0, (1 << n) - 1) a[i] = 1ll * a[i] * x % mod;
  }
}
int s[o], b[o];
void dfs(int x, int fa) {
  s[x] = 1;
  for (int i = h[x]; i; i = w[i].next) {
    int y = w[i].to;
    if (y == fa)
      continue;
    dfs(y, x);
    s[x] += s[y];
    b[s[y]]--;
  }
  if (s[x] != n)
    b[n - s[x]]--;
}
int fac[o], inv[o], c[o];
int main() {
  n = read();
  b[n] = n;
  FOR(i, 1, n - 1) {
    int x = read(), y = read();
    add(x, y);
    add(y, x);
  }
  dfs(1, 0);
  FOR(i, 1, n) b[i] = (b[i] + mod) % mod;
  fac[0] = 1;
  FOR(i, 1, n) fac[i] = 1ll * fac[i - 1] * i % mod;
  inv[n] = KSM(fac[n], mod - 2);
  REP(i, n - 1, 0) inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
  FOR(i, 1, n) b[i] = 1ll * b[i] * fac[i] % mod;
  FOR(i, 1, n) c[n - i] = b[i];
  int t = Make(n << 1);
  NTT(c, t, 1);
  NTT(inv, t, 1);
  FOR(i, 0, (1 << t) - 1) c[i] = 1ll * c[i] * inv[i] % mod;
  NTT(c, t, -1);
  NTT(inv, t, -1);
  FOR(i, 1, n) cout << 1ll * c[n - i] * inv[i] % mod << '\n';
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define o 1000005
#define re register int
#define ll long long
#define g0(a) memset(a, 0, sizeof(a))
#define gc(a, b) memcpy(a, b, sizeof(a))
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define REP(i, a, b) for (int i = a; i >= b; i--)
#define pa pair<int, int>
#define mpp make_pair
#define s1 first
#define s2 second
#define go(x) for (ll i = h[x]; i; i = w[i].next)
using namespace std;
inline int read() {
  register int data = 0, w = 1;
  char ch = 0;
  while (ch != '-' && (ch < '0' || ch > '9'))
    ch = getchar();
  if (ch == '-')
    w = -1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    data = (data << 1) + (data << 3) + (ch ^ 48), ch = getchar();
  return data * w;
}
int h[o], cnt;
struct node {
  int to, next;
} w[o];
void add(int x, int y) {
  ++cnt;
  w[cnt].to = y;
  w[cnt].next = h[x];
  h[x] = cnt;
}
int n, rev[o];
int Make(int n) {
  int t = ceil(log2(n + 1));
  FOR(i, 0, (1 << t) - 1) rev[i] = (rev[i >> 1] >> 1 | (i & 1) << t - 1);
  return t;
}
const int mod = 924844033;
int KSM(int x, int k) {
  int tmp = 1, y = x;
  for (int i = k; i; i >>= 1, y = 1ll * y * y % mod)
    if (i & 1)
      tmp = 1ll * tmp * y % mod;
  return tmp;
}
void Add(int &x, int y) {
  x += y - mod;
  x += x >> 31 & mod;
}
void dec(int &x, int y) {
  x -= y;
  x += x >> 31 & mod;
}
void fix(int &x) { x += x >> 31 & mod; }
void NTT(int a[], int n, int d) {
  FOR(i, 0, (1 << n) - 1) if (i < rev[i]) swap(a[i], a[rev[i]]);
  for (int m = 0; m < n; ++m) {
    int w = KSM(5, mod - 1 + (mod - 1) / (2 << m) * d);
    for (int i = 0; i < 1 << n; i += 2 << m)
      for (int k = i, x = 1; k < i + (1 << m); ++k, x = 1ll * x * w % mod) {
        int t0 = a[k], t1 = 1ll * x * a[k + (1 << m)] % mod;
        Add(a[k], t1);
        fix(a[k + (1 << m)] = t0 - t1);
      }
  }
  if (d == -1) {
    int x = KSM(1 << n, mod - 2);
    FOR(i, 0, (1 << n) - 1) a[i] = 1ll * a[i] * x % mod;
  }
}
int s[o], b[o];
void dfs(int x, int fa) {
  s[x] = 1;
  for (int i = h[x]; i; i = w[i].next) {
    int y = w[i].to;
    if (y == fa)
      continue;
    dfs(y, x);
    s[x] += s[y];
    b[s[y]]--;
  }
  if (s[x] != n)
    b[n - s[x]]--;
}
int fac[o], inv[o], c[o];
int main() {
  n = read();
  b[n] = n;
  FOR(i, 1, n - 1) {
    int x = read(), y = read();
    add(x, y);
    add(y, x);
  }
  dfs(1, 0);
  FOR(i, 1, n) b[i] = (b[i] + mod) % mod;
  fac[0] = 1;
  FOR(i, 1, n) fac[i] = 1ll * fac[i - 1] * i % mod;
  inv[n] = KSM(fac[n], mod - 2);
  REP(i, n - 1, 0) inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
  FOR(i, 1, n) b[i] = 1ll * b[i] * fac[i] % mod;
  FOR(i, 1, n) c[n - i] = b[i];
  int t = Make(n << 1);
  NTT(c, t, 1);
  NTT(inv, t, 1);
  FOR(i, 0, (1 << t) - 1) c[i] = 1ll * c[i] * inv[i] % mod;
  NTT(c, t, -1);
  NTT(inv, t, -1);
  FOR(i, 1, n) cout << 1ll * c[n - i] * inv[i] % mod << '\n';
  return 0;
}