Problem p02279 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
const int MAX = 10005;
const int NIL = -1;

struct Node {
  int p, l, r;
};
Node Tree[MAX];
int n, Depth[MAX];

void print(int u) {
  printf("node %d: ", u);
  printf("parent = %d, ", Tree[u].p);
  printf("depth = %d, ", Depth[u]);

  if (Tree[u].p == NIL)
    printf("root, ");
  else if (Tree[u].l == NIL)
    printf("leaf, ");
  else
    printf("internal node, ");

  printf("[");
  // ????????????????????????????§???????
  int c = Tree[u].l;
  while (c != NIL) {
    printf("%d", c);
    if (Tree[c].r != NIL)
      printf(", ");
    // ?????°?????§?´§??????????????????
    c = Tree[c].r;
  }
  printf("]\n");
}

// ??????????±???±???
void rec(int u, int depth) {
  Depth[u] = depth;
  if (Tree[u].r != NIL) // ?????§???????????????????????±???
    rec(Tree[u].r, depth);
  if (Tree[u].l !=
      NIL) // ????????§??????????????±?????????????????±?????±??? + 1
    rec(Tree[u].l, depth + 1);
}
int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    Tree[i].p = Tree[i].l = Tree[i].r = NIL;
  }
  int v, num, c, l, root;
  for (int i = 0; i < n; i++) {
    // v?????????????????? ???num???v????????????????????°
    scanf("%d %d", &v, &num);
    for (int j = 0; j < num; j++) {
      scanf("%d", &c);

      //??????????????§?????? ??? ?´§????????§????????????
      // l??°????????????????????????????°?????????????????????????l????´§????????§??????
      if (j == 0)
        Tree[v].l = c;
      else
        Tree[l].r = c;
      l = c;
      // ????????¶??????
      Tree[c].p = v;
    }
  }
  // ???????????????
  for (int i = 0; i < n; i++) {
    if (Tree[i].p == NIL)
      root = i;
  }

  rec(root, 0);
  for (int i = 0; i < n; i++)
    print(i);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
const int MAX = 100005;
const int NIL = -1;

struct Node {
  int p, l, r;
};
Node Tree[MAX];
int n, Depth[MAX];

void print(int u) {
  printf("node %d: ", u);
  printf("parent = %d, ", Tree[u].p);
  printf("depth = %d, ", Depth[u]);

  if (Tree[u].p == NIL)
    printf("root, ");
  else if (Tree[u].l == NIL)
    printf("leaf, ");
  else
    printf("internal node, ");

  printf("[");
  // ????????????????????????????§???????
  int c = Tree[u].l;
  while (c != NIL) {
    printf("%d", c);
    if (Tree[c].r != NIL)
      printf(", ");
    // ?????°?????§?´§??????????????????
    c = Tree[c].r;
  }
  printf("]\n");
}

// ??????????±???±???
void rec(int u, int depth) {
  Depth[u] = depth;
  if (Tree[u].r != NIL) // ?????§???????????????????????±???
    rec(Tree[u].r, depth);
  if (Tree[u].l !=
      NIL) // ????????§??????????????±?????????????????±?????±??? + 1
    rec(Tree[u].l, depth + 1);
}
int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    Tree[i].p = Tree[i].l = Tree[i].r = NIL;
  }
  int v, num, c, l, root;
  for (int i = 0; i < n; i++) {
    // v?????????????????? ???num???v????????????????????°
    scanf("%d %d", &v, &num);
    for (int j = 0; j < num; j++) {
      scanf("%d", &c);

      //??????????????§?????? ??? ?´§????????§????????????
      // l??°????????????????????????????°?????????????????????????l????´§????????§??????
      if (j == 0)
        Tree[v].l = c;
      else
        Tree[l].r = c;
      l = c;
      // ????????¶??????
      Tree[c].p = v;
    }
  }
  // ???????????????
  for (int i = 0; i < n; i++) {
    if (Tree[i].p == NIL)
      root = i;
  }

  rec(root, 0);
  for (int i = 0; i < n; i++)
    print(i);
  return 0;
}