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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

class tree {
public:
  void putparent(int n);
  void putleft(int n);
  void putright(int n);
  int getparent();
  string gettype();
  int getleft();
  int getright();
  tree();

private:
  int parent;
  int left_child;
  int right;
};

typedef struct tree Tree;

tree::tree() {
  parent = -1;
  left_child = -1;
  right = -1;
}

void tree::putparent(int n) {
  parent = n;
  return;
}

void tree::putleft(int n) {
  left_child = n;
  return;
}

void tree::putright(int n) {
  right = n;
  return;
}

int tree::getparent() { return parent; }

string tree::gettype() {
  if (getparent() == -1)
    return "root";
  else if (getleft() == -1)
    return "leaf";
  else
    return "internal node";
}

int tree::getleft() { return left_child; }

int tree::getright() { return right; }

int getdepth(Tree a[], int n) {
  int ans = 0;
  if (a[n].getparent() != -1)
    return getdepth(a, a[n].getparent()) + 1;
  else
    return 0;
}

int main() {
  int n;
  cin >> n;
  Tree t[100000];
  int v, d, c, l;
  for (int i = 0; i < n; i++) {
    cin >> v >> d;
    for (int j = 0; j < d; j++) {
      cin >> c;
      if (j == 0)
        t[v].putleft(c);
      else
        t[l].putright(c);
      l = c;
      t[c].putparent(v);
    }
  }
  for (int i = 0; i < n; i++) {
    cout << "node " << i << ": ";
    cout << "parent = " << t[i].getparent() << ", ";
    cout << "depth = " << getdepth(t, i) << ", ";
    cout << t[i].gettype() << ", ";
    cout << "[";
    if (t[i].getleft() != -1) {
      cout << t[i].getleft();
      l = t[i].getleft();
      while (t[l].getright() != -1) {
        cout << ", ";
        cout << t[l].getright();
        l = t[l].getright();
      }
    }
    cout << "]" << endl;
  }
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  int tree[100000][2];
  // tree[i][0]:parent of node i, tree[i][1]: depth of node i
  for (int i = 0; i < n; i++) {
    tree[i][0] = -1;
    tree[i][1] = 0;
  }
  int node[100000];
  int k[100000];
  int c[100000][100000];
  for (int i = 0; i < n; i++) {
    cin >> node[i] >> k[i];
    for (int j = 0; j < k[i]; j++) {
      cin >> c[node[i]][j];
      tree[c[node[i]][j]][0] = node[i];
      tree[c[node[i]][j]][1] = tree[node[i]][1] + 1;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << "node " << node[i] << ": parent = " << tree[node[i]][0]
         << ", depth = " << tree[node[i]][1] << ", ";
    if (tree[node[i]][0] == -1)
      cout << "root, ";
    else if (k[node[i]] == 0)
      cout << "leaf, ";
    else
      cout << "internal node, ";
    cout << "[";
    for (int j = 0; j < k[node[i]]; j++) {
      if (j == k[node[i]] - 1)
        cout << c[node[i]][j];
      else
        cout << c[node[i]][j] << ", ";
    }
    cout << "]" << endl;
  }
  return 0;
}