Problem p03204 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define re register
#define ui unsigned int
#define ull unsigned long long
int c[200100], f[200100], fc[200100], n;
struct eg {
  int to;
  eg *nx;
} e[200100], *la[200100], *cnt = e;
inline void addE(re int a, re int b) {
  *++cnt = (eg){b, la[a]};
  la[a] = cnt;
  *++cnt = (eg){a, la[b]};
  la[b] = cnt;
}
struct nd {
  int x;
  nd *l, *r;
} pl[5000100], *cct = pl;
nd *no[200100];
nd *meg(re nd *a, re nd *b) {
  if (!a)
    return b;
  if (!b)
    return a;
  a->x += b->x;
  a->l = meg(a->l, b->l);
  a->r = meg(a->r, b->r);
  return a;
}
int qus(re nd *a, re int l, re int r, re int l1) {
  if (!a)
    return 0;
  if (l == r)
    return a->x;
  re int mid = (l + r) / 2;
  if (l1 <= mid)
    return qus(a->l, l, mid, l1);
  else
    return (a->l ? a->l->x : 0) + qus(a->r, mid + 1, r, l1);
}
void add(re nd *&a, re int l, re int r, re int l1, re int x1) {
  if (!a)
    a = ++cct;
  a->x += x1;
  if (l == r)
    return;
  re int mid = (l + r) / 2;
  if (l1 <= mid)
    add(a->l, l, mid, l1, x1);
  else
    x1 += (a->l ? a->l->x : 0), a->l = 0, add(a->r, mid + 1, r, l1, x1);
}
void dfs(re int a, re int fa) {
  for (re eg *i = la[a]; i; i = i->nx)
    if (i->to != fa) {
      f[i->to] = std::max(a, f[a]);
      dfs(i->to, a);
      fc[i->to] = qus(no[i->to], 1, n, f[a]);
      no[a] = meg(no[a], no[i->to]);
    }
  add(no[a], 1, n, a, 1);
}
void dfs1(re int a, re int fa, re int x1) {
  for (re eg *i = la[a]; i; i = i->nx)
    if (i->to != fa)
      x1 += fc[i->to];
  c[a] = x1;
  x1++;
  for (re eg *i = la[a]; i; i = i->nx)
    if (i->to != fa)
      dfs1(i->to, a, x1 - fc[i->to]);
}
int main() {
  re int x, y;
  scanf("%d", &n);
  for (re int i = 1; i < n; i++)
    scanf("%d%d", &x, &y), addE(x, y);
  dfs(1, 0);
  dfs1(1, 0, 0);
  for (re int i = 2; i <= n; i++)
    printf("%d ", c[i]);
}

Fixed submission:
#include <bits/stdc++.h>
#define re register
#define ui unsigned int
#define ull unsigned long long
int c[200100], f[200100], fc[200100], n;
struct eg {
  int to;
  eg *nx;
} e[400100], *la[200100], *cnt = e;
inline void addE(re int a, re int b) {
  *++cnt = (eg){b, la[a]};
  la[a] = cnt;
  *++cnt = (eg){a, la[b]};
  la[b] = cnt;
}
struct nd {
  int x;
  nd *l, *r;
} pl[5000100], *cct = pl;
nd *no[200100];
nd *meg(re nd *a, re nd *b) {
  if (!a)
    return b;
  if (!b)
    return a;
  a->x += b->x;
  a->l = meg(a->l, b->l);
  a->r = meg(a->r, b->r);
  return a;
}
int qus(re nd *a, re int l, re int r, re int l1) {
  if (!a)
    return 0;
  if (l == r)
    return a->x;
  re int mid = (l + r) / 2;
  if (l1 <= mid)
    return qus(a->l, l, mid, l1);
  else
    return (a->l ? a->l->x : 0) + qus(a->r, mid + 1, r, l1);
}
void add(re nd *&a, re int l, re int r, re int l1, re int x1) {
  if (!a)
    a = ++cct;
  a->x += x1;
  if (l == r)
    return;
  re int mid = (l + r) / 2;
  if (l1 <= mid)
    add(a->l, l, mid, l1, x1);
  else
    x1 += (a->l ? a->l->x : 0), a->l = 0, add(a->r, mid + 1, r, l1, x1);
}
void dfs(re int a, re int fa) {
  for (re eg *i = la[a]; i; i = i->nx)
    if (i->to != fa) {
      f[i->to] = std::max(a, f[a]);
      dfs(i->to, a);
      fc[i->to] = qus(no[i->to], 1, n, f[a]);
      no[a] = meg(no[a], no[i->to]);
    }
  add(no[a], 1, n, a, 1);
}
void dfs1(re int a, re int fa, re int x1) {
  for (re eg *i = la[a]; i; i = i->nx)
    if (i->to != fa)
      x1 += fc[i->to];
  c[a] = x1;
  x1++;
  for (re eg *i = la[a]; i; i = i->nx)
    if (i->to != fa)
      dfs1(i->to, a, x1 - fc[i->to]);
}
int main() {
  re int x, y;
  scanf("%d", &n);
  for (re int i = 1; i < n; i++)
    scanf("%d%d", &x, &y), addE(x, y);
  dfs(1, 0);
  dfs1(1, 0, 0);
  for (re int i = 2; i <= n; i++)
    printf("%d ", c[i]);
}