Problem p02728 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define re register
#define M 1000000007
inline int read() {
  re int t = 0;
  re char v = getchar();
  while (v < '0')
    v = getchar();
  while (v >= '0') {
    t = (t << 3) + (t << 1) + v - 48;
    v = getchar();
  }
  return t;
}
using namespace std;
int n, head[2000002], cnt, ans[2000002], fa[2000002], f[2000002], jc[2000002],
    num[2000002], inv[2000002], siz[2000002], siz1[2000002];
struct edge {
  int to, next;
} e[2000002];
inline int C(re int x, re int y) {
  return 1ll * jc[x] * inv[y] % M * inv[x - y] % M;
}
inline void add(re int x, re int y) {
  e[++cnt].to = y;
  e[cnt].next = head[x];
  head[x] = cnt;
}
inline void dp(re int x, re int y) {
  ans[x] = 1;
  fa[x] = y;
  siz[x] = 1;
  for (re int i = head[x]; i; i = e[i].next)
    if (e[i].to ^ y) {
      dp(e[i].to, x);
      ans[x] = 1ll * ans[x] * ans[e[i].to] % M *
               C(siz[x] - 1 + siz[e[i].to], siz[e[i].to]) % M;
      siz[x] += siz[e[i].to];
    }
}
inline int ksm(re int x, re int y) {
  re int ans = 1;
  while (y) {
    if (y & 1)
      ans = 1ll * ans * x % M;
    x = 1ll * x * x % M;
    y >>= 1;
  }
  return ans;
}
inline void dp1(re int x, re int y) {
  if (x != 1)
    ans[x] = 1ll * ans[x] * y % M * C(siz[x] - 1 + n - siz[x], n - siz[x]) % M;
  for (re int i = head[x]; i; i = e[i].next)
    if (e[i].to ^ fa[x])
      dp1(e[i].to, 1ll * ans[x] * ksm(ans[e[i].to], M - 2) % M *
                       ksm(C(n - 1, siz[e[i].to]), M - 2) % M);
}
signed main() {
  n = read();
  jc[0] = 1;
  n *= 2;
  for (re int i = 1; i <= n; ++i)
    jc[i] = 1ll * jc[i - 1] * i % M;
  inv[n] = ksm(jc[n], M - 2);
  inv[0] = 1;
  for (re int i = n - 1; i; --i)
    inv[i] = 1ll * (i + 1) * inv[i + 1] % M;
  n /= 2;
  for (re int i = 1, x, y; i < n; ++i) {
    x = read();
    y = read();
    add(x, y);
    add(y, x);
  }
  dp(1, 1);
  dp1(1, 1);
  for (re int i = 1; i <= n; ++i)
    printf("%d\\n", ans[i]);
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define re register
#define M 1000000007
inline int read() {
  re int t = 0;
  re char v = getchar();
  while (v < '0')
    v = getchar();
  while (v >= '0') {
    t = (t << 3) + (t << 1) + v - 48;
    v = getchar();
  }
  return t;
}
using namespace std;
int n, head[100002], cnt, ans[100002], fa[100002], f[100002], jc[100002],
    num[100002], inv[100002], siz[100002], siz1[100002];
struct edge {
  int to, next;
} e[200002];
inline int C(re int x, re int y) {
  return 1ll * jc[x] * inv[y] % M * inv[x - y] % M;
}
inline void add(re int x, re int y) {
  e[++cnt].to = y;
  e[cnt].next = head[x];
  head[x] = cnt;
}
inline void dp(re int x, re int y) {
  ans[x] = 1;
  fa[x] = y;
  siz[x] = 1;
  for (re int i = head[x]; i; i = e[i].next)
    if (e[i].to ^ y) {
      dp(e[i].to, x);
      ans[x] = 1ll * ans[x] * ans[e[i].to] % M *
               C(siz[x] - 1 + siz[e[i].to], siz[e[i].to]) % M;
      siz[x] += siz[e[i].to];
    }
}
inline int ksm(re int x, re int y) {
  re int ans = 1;
  while (y) {
    if (y & 1)
      ans = 1ll * ans * x % M;
    x = 1ll * x * x % M;
    y >>= 1;
  }
  return ans;
}
inline void dp1(re int x, re int y) {
  if (x != 1)
    ans[x] = 1ll * ans[x] * y % M * C(siz[x] - 1 + n - siz[x], n - siz[x]) % M;
  for (re int i = head[x]; i; i = e[i].next)
    if (e[i].to ^ fa[x])
      dp1(e[i].to, 1ll * ans[x] * ksm(ans[e[i].to], M - 2) % M *
                       ksm(C(n - 1, siz[e[i].to]), M - 2) % M);
}
signed main() {
  n = read();
  jc[0] = 1;
  n *= 2;
  for (re int i = 1; i <= n; ++i)
    jc[i] = 1ll * jc[i - 1] * i % M;
  inv[n] = ksm(jc[n], M - 2);
  inv[0] = 1;
  for (re int i = n - 1; i; --i)
    inv[i] = 1ll * (i + 1) * inv[i + 1] % M;
  n /= 2;
  for (re int i = 1, x, y; i < n; ++i) {
    x = read();
    y = read();
    add(x, y);
    add(y, x);
  }
  dp(1, 1);
  dp1(1, 1);
  for (re int i = 1; i <= n; ++i)
    printf("%d\\n", ans[i]);
}