Problem p03991 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cctype>
#include <cstdio>

using namespace std;

const int MAXN = 6e5 + 7;
const int MOD = 924844033;

inline int read() {
  char in = getchar();
  int res = 0, flag = 1;
  while (!isdigit(in)) {
    if (in == '-')
      flag = -1;
    in = getchar();
  }
  while (isdigit(in)) {
    res = (res << 1) + (res << 3) + in - '0';
    in = getchar();
  }
  return res * flag;
}

int n, Lim = 1, Log;
int cnt[MAXN], siz[MAXN], P, a[MAXN << 1], b[MAXN << 1];
int fac[MAXN + 7], rev[MAXN], ifac[MAXN + 7];
int dex, head[MAXN], nxt[MAXN << 1], to[MAXN << 1];

inline void Link(int x, int y) {
  ++dex;
  nxt[dex] = head[x];
  to[dex] = y;
  head[x] = dex;
}

inline int fpm(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1)
      res = 1ll * x * res % MOD;
    x = 1ll * x * x % MOD;
    y >>= 1;
  }
  return res;
}

void dfs(int u, int fa) {
  siz[u] = 1;
  for (int i = head[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == fa)
      continue;
    dfs(v, u);
    siz[u] += siz[v];
  }
  --cnt[siz[u]];
  --cnt[n - siz[u]];
}

inline void Transform(int *A, int type) {
  for (int i = 1; i < Lim; ++i)
    if (i < rev[i])
      swap(A[i], A[rev[i]]);
  for (int mid = 1; mid < Lim; mid <<= 1) {
    int Wn = fpm(5, ((MOD - 1) / mid) >> 1);
    if (type == -1)
      Wn = fpm(Wn, MOD - 2);
    for (int r = (mid << 1), j = 0; j < Lim; j += r) {
      for (int l = 0, k = 1; l < mid; ++l, k = 1ll * Wn * k % MOD) {
        int x = A[j + l];
        int y = 1ll * A[j + l + mid] * k % MOD;
        A[j + l] = (x + y) % MOD;
        A[j + l + mid] = (1ll * x - y + MOD) % MOD;
      }
    }
  }
  int C = fpm(Lim, MOD - 2);
  if (type == -1)
    for (int i = 0; i < Lim; ++i)
      A[i] = 1ll * A[i] * C % MOD;
}

inline void init() {
  n = read();
  for (int i = 1; i < n; ++i) {
    int x = read();
    int y = read();
    Link(x, y);
    Link(y, x);
  }
  dfs(1, 0);
  cnt[n] = n;
  fac[0] = 1;
  n <<= 1;
  n += 2;
  while (Lim < n)
    Lim <<= 1, ++Log;
  n -= 2;
  n >>= 1;

  for (int i = 1; i < Lim; ++i)
    rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (Log - 1));
  for (int i = 1; i <= MAXN; ++i)
    fac[i] = 1ll * fac[i - 1] * i % MOD;
  ifac[MAXN] = fpm(fac[MAXN], MOD - 2);
  for (int i = MAXN - 1; i >= 0; --i)
    ifac[i] = 1ll * ifac[i + 1] * (i + 1) % MOD;

  for (int i = 1; i <= n; ++i)
    a[i] = 1ll * cnt[i] * fac[i] % MOD;
  for (int i = 0; i <= n; ++i)
    b[i] = ifac[n - i];
}

inline void solve() {
  Transform(a, 1);
  Transform(b, 1);
  for (int i = 0; i < Lim; ++i)
    a[i] = 1ll * a[i] * b[i] % MOD;
  Transform(a, -1);
  for (int i = 1; i <= n; ++i)
    printf("%lld\n", (1ll * a[n + i] * ifac[i] % MOD + MOD) % MOD);
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("AT2064.in", "r", stdin);
  freopen("AT2064.out", "w", stdout);
#endif

  init();
  solve();
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cctype>
#include <cstdio>

using namespace std;

const int MAXN = 6e5 + 7;
const int MOD = 924844033;

inline int read() {
  char in = getchar();
  int res = 0, flag = 1;
  while (!isdigit(in)) {
    if (in == '-')
      flag = -1;
    in = getchar();
  }
  while (isdigit(in)) {
    res = (res << 1) + (res << 3) + in - '0';
    in = getchar();
  }
  return res * flag;
}

int n, Lim = 1, Log;
int cnt[MAXN], siz[MAXN], P, a[MAXN << 1], b[MAXN << 1];
int fac[MAXN + 7], rev[MAXN], ifac[MAXN + 7];
int dex, head[MAXN], nxt[MAXN << 1], to[MAXN << 1];

inline void Link(int x, int y) {
  ++dex;
  nxt[dex] = head[x];
  to[dex] = y;
  head[x] = dex;
}

inline int fpm(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1)
      res = 1ll * x * res % MOD;
    x = 1ll * x * x % MOD;
    y >>= 1;
  }
  return res;
}

void dfs(int u, int fa) {
  siz[u] = 1;
  for (int i = head[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == fa)
      continue;
    dfs(v, u);
    siz[u] += siz[v];
  }
  --cnt[siz[u]];
  --cnt[n - siz[u]];
}

inline void Transform(int *A, int type) {
  for (int i = 1; i < Lim; ++i)
    if (i < rev[i])
      swap(A[i], A[rev[i]]);
  for (int mid = 1; mid < Lim; mid <<= 1) {
    int Wn = fpm(5, ((MOD - 1) / mid) >> 1);
    if (type == -1)
      Wn = fpm(Wn, MOD - 2);
    for (int r = (mid << 1), j = 0; j < Lim; j += r) {
      for (int l = 0, k = 1; l < mid; ++l, k = 1ll * Wn * k % MOD) {
        int x = A[j + l];
        int y = 1ll * A[j + l + mid] * k % MOD;
        A[j + l] = (x + y) % MOD;
        A[j + l + mid] = (1ll * x - y + MOD) % MOD;
      }
    }
  }
  int C = fpm(Lim, MOD - 2);
  if (type == -1)
    for (int i = 0; i < Lim; ++i)
      A[i] = 1ll * A[i] * C % MOD;
}

inline void init() {
  n = read();
  for (int i = 1; i < n; ++i) {
    int x = read();
    int y = read();
    Link(x, y);
    Link(y, x);
  }
  dfs(1, 0);
  cnt[n] = n;
  fac[0] = 1;
  n <<= 1;
  n += 2;
  while (Lim < n)
    Lim <<= 1, ++Log;
  n -= 2;
  n >>= 1;

  for (int i = 1; i < Lim; ++i)
    rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (Log - 1));
  for (int i = 1; i <= MAXN; ++i)
    fac[i] = 1ll * fac[i - 1] * i % MOD;
  ifac[MAXN] = fpm(fac[MAXN], MOD - 2);
  for (int i = MAXN - 1; i >= 0; --i)
    ifac[i] = 1ll * ifac[i + 1] * (i + 1) % MOD;

  for (int i = 1; i <= n; ++i)
    a[i] = 1ll * cnt[i] * fac[i] % MOD;
  for (int i = 0; i <= n; ++i)
    b[i] = ifac[n - i];
}

inline void solve() {
  Transform(a, 1);
  Transform(b, 1);
  for (int i = 0; i < Lim; ++i)
    a[i] = 1ll * a[i] * b[i] % MOD;
  Transform(a, -1);
  for (int i = 1; i <= n; ++i)
    printf("%lld\n", (1ll * a[n + i] * ifac[i] % MOD + MOD) % MOD);
}

int main() {
  init();
  solve();
  return 0;
}