Problem p03991 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X)                                                                 \
  int(X);                                                                      \
  scanf("%d", &X)
#define DRII(X, Y)                                                             \
  int X, Y;                                                                    \
  scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z)                                                         \
  int X, Y, Z;                                                                 \
  scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET                                                                  \
  int ___T, case_n = 1;                                                        \
  scanf("%d ", &___T);                                                         \
  while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<pair<int, int>>
#define PLL pair<long long, long long>
#define VPLL vector<pair<long long, long long>>
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 924844033;
const int R_R = 2000;
const int SIZE = 1e6 + 10;
inline int pow(long long n, int k, int m) {
  unsigned i;
  int a;
  for (a = i = 1; i <= k; i *= 2, n = (n * n) % m)
    if (k & i)
      a = (a * n) % m;
  return a;
}
inline int rev(int n, int k) {
  int i = 0;
  while (k--)
    (i <<= 1) += n & 1, n /= 2;
  return i;
}
const long long p = MOD, r = 10;
void ntt(bool f, int &n, int s[]) {
  int i, j, k;
  long long x, w;
  for (j = 1, k = 0; j < n; j <<= 1, k++)
    ;
  for (; n < j; n++)
    s[n] = 0;
  for (i = 0; i < n; i++)
    if (i < rev(i, k))
      swap(s[i], s[rev(i, k)]);
  for (i = 2; i <= n; i *= 2) {
    w = pow(pow(r, (p - 1) / n, p), f ? p - 1 - n / i : n / i, p);
    for (j = 0; j < n; j += i)
      for (k = 0, x = 1; k < i / 2; k++) {
        int &a = s[j + k], &b = s[j + k + i / 2];
        b = (b * x) % p;
        a = (a * 1ll + b) % p;
        b = (a + p + p - b - b) % p;
        x = x * w % p;
      }
  }
  x = pow(n, p - 2, p);
  if (f)
    for (j = 0; j < n; j++)
      s[j] = (s[j] * x) % p;
}
void mul(int n, int a[], int b[]) {
  for (int i = 0; i < n; i++)
    a[i] = (1ll * a[i] * b[i]) % p;
}
LL fac[SIZE], inv[SIZE];
LL mypow(LL x, LL y) {
  LL res = 1;
  while (y) {
    if (y & 1)
      res = res * x % MOD;
    y >>= 1;
    x = x * x % MOD;
  }
  return res;
}
LL C(int x, int y) {
  if (y < 0 || y > x)
    return 0;
  return fac[x] * inv[y] % MOD * inv[x - y] % MOD;
}
void build() {
  assert(MOD >= SIZE);
  fac[0] = 1;
  REPP(i, 1, SIZE) fac[i] = fac[i - 1] * i % MOD;
  inv[SIZE - 1] = mypow(fac[SIZE - 1], MOD - 2);
  for (int i = SIZE - 2; i >= 0; i--)
    inv[i] = inv[i + 1] * (i + 1) % MOD;
}
int s[1000000], t[1000000];
int num[SIZE], N;
VI e[SIZE];
bool u[SIZE];
int cnt[SIZE];
void dfs(int x) {
  u[x] = 1;
  num[x] = 1;
  REP(i, SZ(e[x])) {
    int y = e[x][i];
    if (u[y])
      continue;
    dfs(y);
    num[x] += num[y];
    cnt[num[y]]++;
  }
  cnt[N - num[x]]++;
}
int an[SIZE];
void ADD(int &x, LL v) {
  x = (x + v) % MOD;
  if (x < 0)
    x += MOD;
}
int main() {
  build();
  RI(N);
  REPP(i, 1, N) {
    DRII(x, y);
    e[x].PB(y);
    e[y].PB(x);
  }
  dfs(1);
  for (int i = 1; i <= N; i += R_R) {
    int two = 1;
    while (two <= min(i + R_R - 1, N))
      two *= 2;
    memset(t, 0, sizeof(int) * (two + 1));
    memset(s, 0, sizeof(int) * (two + 1));
    int up = 0;
    for (int j = min(i + R_R - 1, N); j >= i; j--) {
      up++;
      for (int k = up; k > 0; k--) {
        t[k] += t[k - 1];
        if (t[k] >= MOD)
          t[k] -= MOD;
      }
      t[0] += cnt[j];
      while (up > 0 && t[up] == 0)
        up--;
    }
    REP(j, i + 1) s[j] = C(i, j);
    int n2 = two;
    up = two;
    ntt(0, n2, s);
    ntt(0, up, t);
    mul(up, t, s);
    ntt(1, up, t);
    REP(i, n2) ADD(an[i], t[i]);
  }
  REPP(i, 1, N + 1) {
    an[i] = (N * C(N, i) % MOD - an[i]) % MOD;
    if (an[i] < 0)
      an[i] += MOD;
    printf("%d\n", an[i]);
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X)                                                                 \
  int(X);                                                                      \
  scanf("%d", &X)
#define DRII(X, Y)                                                             \
  int X, Y;                                                                    \
  scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z)                                                         \
  int X, Y, Z;                                                                 \
  scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET                                                                  \
  int ___T, case_n = 1;                                                        \
  scanf("%d ", &___T);                                                         \
  while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<pair<int, int>>
#define PLL pair<long long, long long>
#define VPLL vector<pair<long long, long long>>
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 924844033;
const int R_R = 5000;
const int SIZE = 1e6 + 10;
inline int pow(long long n, int k, int m) {
  unsigned i;
  int a;
  for (a = i = 1; i <= k; i *= 2, n = (n * n) % m)
    if (k & i)
      a = (a * n) % m;
  return a;
}
inline int rev(int n, int k) {
  int i = 0;
  while (k--)
    (i <<= 1) += n & 1, n /= 2;
  return i;
}
const long long p = MOD, r = 10;
void ntt(bool f, int &n, int s[]) {
  int i, j, k;
  long long x, w;
  for (j = 1, k = 0; j < n; j <<= 1, k++)
    ;
  for (; n < j; n++)
    s[n] = 0;
  for (i = 0; i < n; i++)
    if (i < rev(i, k))
      swap(s[i], s[rev(i, k)]);
  for (i = 2; i <= n; i *= 2) {
    w = pow(pow(r, (p - 1) / n, p), f ? p - 1 - n / i : n / i, p);
    for (j = 0; j < n; j += i)
      for (k = 0, x = 1; k < i / 2; k++) {
        int &a = s[j + k], &b = s[j + k + i / 2];
        b = (b * x) % p;
        a = (a * 1ll + b) % p;
        b = (a + p + p - b - b) % p;
        x = x * w % p;
      }
  }
  x = pow(n, p - 2, p);
  if (f)
    for (j = 0; j < n; j++)
      s[j] = (s[j] * x) % p;
}
void mul(int n, int a[], int b[]) {
  for (int i = 0; i < n; i++)
    a[i] = (1ll * a[i] * b[i]) % p;
}
LL fac[SIZE], inv[SIZE];
LL mypow(LL x, LL y) {
  LL res = 1;
  while (y) {
    if (y & 1)
      res = res * x % MOD;
    y >>= 1;
    x = x * x % MOD;
  }
  return res;
}
LL C(int x, int y) {
  if (y < 0 || y > x)
    return 0;
  return fac[x] * inv[y] % MOD * inv[x - y] % MOD;
}
void build() {
  assert(MOD >= SIZE);
  fac[0] = 1;
  REPP(i, 1, SIZE) fac[i] = fac[i - 1] * i % MOD;
  inv[SIZE - 1] = mypow(fac[SIZE - 1], MOD - 2);
  for (int i = SIZE - 2; i >= 0; i--)
    inv[i] = inv[i + 1] * (i + 1) % MOD;
}
int s[1000000], t[1000000];
int num[SIZE], N;
VI e[SIZE];
bool u[SIZE];
int cnt[SIZE];
void dfs(int x) {
  u[x] = 1;
  num[x] = 1;
  REP(i, SZ(e[x])) {
    int y = e[x][i];
    if (u[y])
      continue;
    dfs(y);
    num[x] += num[y];
    cnt[num[y]]++;
  }
  cnt[N - num[x]]++;
}
int an[SIZE];
void ADD(int &x, LL v) {
  x = (x + v) % MOD;
  if (x < 0)
    x += MOD;
}
int main() {
  build();
  RI(N);
  REPP(i, 1, N) {
    DRII(x, y);
    e[x].PB(y);
    e[y].PB(x);
  }
  dfs(1);
  for (int i = 1; i <= N; i += R_R) {
    int two = 1;
    while (two <= min(i + R_R - 1, N))
      two *= 2;
    memset(t, 0, sizeof(int) * (two + 1));
    memset(s, 0, sizeof(int) * (two + 1));
    int up = 0;
    for (int j = min(i + R_R - 1, N); j >= i; j--) {
      up++;
      for (int k = up; k > 0; k--) {
        t[k] += t[k - 1];
        if (t[k] >= MOD)
          t[k] -= MOD;
      }
      t[0] += cnt[j];
      while (up > 0 && t[up] == 0)
        up--;
    }
    REP(j, i + 1) s[j] = C(i, j);
    int n2 = two;
    up = two;
    ntt(0, n2, s);
    ntt(0, up, t);
    mul(up, t, s);
    ntt(1, up, t);
    REP(i, n2) ADD(an[i], t[i]);
  }
  REPP(i, 1, N + 1) {
    an[i] = (N * C(N, i) % MOD - an[i]) % MOD;
    if (an[i] < 0)
      an[i] += MOD;
    printf("%d\n", an[i]);
  }
  return 0;
}