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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <list>
#include <string>
#include <vector>
// static const int	RootParentID = -1;
static const int NIL = -1;
class node {
private:
  int Parent;
  int LeftChild;
  int RightBro;

public:
  node() { Parent = LeftChild = RightBro = NIL; }

  void AddParent(int id) {
    Parent = id;
    return;
  }
  void AddRightBro(int id) {
    RightBro = id;
    return;
  }
  void AddLeftChild(int id) {
    LeftChild = id;
    return;
  }
  int GetParent() { return Parent; }
  int GetLeftChild() { return LeftChild; }
  int GetRightBro() { return RightBro; }
  int GetSibling(const std::vector<node> &nodes) {
    if (Parent != NIL) {

      if (RightBro != NIL) {
        return RightBro;
      } else {
        // std::cout << nodes[nodes[Parent].LeftChild].RightBro << std::endl;;
        return nodes[nodes[Parent].LeftChild].RightBro == NIL
                   ? NIL
                   : nodes[Parent].LeftChild;
      }

    } else
      return NIL;
  }
  int GetDegree(const std::vector<node> &nodes) {
    return LeftChild == NIL ? 0 : (nodes[LeftChild].RightBro == NIL ? 1 : 2);
  }
  int CheckDepth(const std::vector<node> &nodes) {
    int CheckNodeParent = Parent;
    int cnt = 0;
    while (CheckNodeParent != NIL) {
      ++cnt;
      CheckNodeParent = nodes[CheckNodeParent].Parent;
    }
    return cnt;
  }
  int CheckHeight(const std::vector<node> &nodes, node id) {

    int CheckChildLeft = id.LeftChild,
        CheckChildRight =
            id.LeftChild == NIL ? NIL : nodes[id.LeftChild].RightBro;

    int h1 = 0, h2 = 0;
    if (CheckChildLeft != NIL) {

      h1 = CheckHeight(nodes, nodes[CheckChildLeft]) + 1;
    }
    if (CheckChildRight != NIL) {
      h2 = CheckHeight(nodes, nodes[CheckChildRight]) + 1;
    }
    return std::max(h1, h2);
  }
};
int main(void) {
  int n;
  std::cin >> n;
  int id;
  const int k = 2;
  int child;
  std::vector<node> nodes(n + 1);
  for (int i = 0; i < n; i++) {
    std::cin >> id;
    std::vector<int> v(k + 1);

    for (int j = 0; j < k; ++j) {
      std::cin >> child;
      v[j] = child;
    }
    v[k] = NIL;
    for (int j = 0; j < k; ++j) {
      if (v[j] == NIL) {
        std::swap(v[j], v[j + 1]);
      }
    }

    for (int j = 0; j < k; ++j) {
      if (v[j] != NIL) {
        nodes[v[j]].AddParent(id);
        nodes[v[j]].AddRightBro(v[j + 1]);
      }
    }
    nodes[id].AddLeftChild(v[0]);
  }
  for (int i = 0; i < n; ++i) {
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, "
           "height = %d, %s\\n",
           i, nodes[i].GetParent(), nodes[i].GetSibling(nodes),
           nodes[i].GetDegree(nodes), nodes[i].CheckDepth(nodes),
           nodes[i].CheckHeight(nodes, nodes[i]),
           (nodes[i].GetParent() == NIL
                ? "root"
                : (nodes[i].GetLeftChild() == NIL ? "leaf" : "internal node")));
  }
  // system("pause");
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <list>
#include <string>
#include <vector>
// static const int	RootParentID = -1;
static const int NIL = -1;
class node {
private:
  int Parent;
  int LeftChild;
  int RightBro;

public:
  node() { Parent = LeftChild = RightBro = NIL; }

  void AddParent(int id) {
    Parent = id;
    return;
  }
  void AddRightBro(int id) {
    RightBro = id;
    return;
  }
  void AddLeftChild(int id) {
    LeftChild = id;
    return;
  }
  int GetParent() { return Parent; }
  int GetLeftChild() { return LeftChild; }
  int GetRightBro() { return RightBro; }
  int GetSibling(const std::vector<node> &nodes) {
    if (Parent != NIL) {
      return RightBro == NIL ? nodes[Parent].LeftChild : RightBro;
    } else
      return NIL;
  }
  int GetDegree(const std::vector<node> &nodes) {
    return LeftChild == NIL ? 0 : (nodes[LeftChild].RightBro == NIL ? 1 : 2);
  }
  int CheckDepth(const std::vector<node> &nodes) {
    int CheckNodeParent = Parent;
    int cnt = 0;
    while (CheckNodeParent != NIL) {
      ++cnt;
      CheckNodeParent = nodes[CheckNodeParent].Parent;
    }
    return cnt;
  }
  int CheckHeight(const std::vector<node> &nodes, node id) {

    int CheckChildLeft = id.LeftChild,
        CheckChildRight = nodes[id.LeftChild].RightBro;

    int h1 = 0, h2 = 0;
    if (CheckChildLeft != NIL) {
      h1 = CheckHeight(nodes, nodes[CheckChildLeft]) + 1;
    }
    if (CheckChildRight != NIL) {
      h2 = CheckHeight(nodes, nodes[CheckChildRight]) + 1;
    }
    return std::max(h1, h2);
  }
};
int main(void) {
  int n;
  std::cin >> n;
  int id;
  const int k = 2;
  int child;
  std::vector<node> nodes(n + 1);
  for (int i = 0; i < n; i++) {
    std::cin >> id;
    std::vector<int> v(k + 1);

    for (int j = 0; j < k; ++j) {
      std::cin >> child;
      v[j] = child;
    }
    v[k] = NIL;
    for (int j = 0; j < k; ++j) {
      if (v[j] != NIL) {
        nodes[v[j]].AddParent(id);
        nodes[v[j]].AddRightBro(v[j + 1]);
      }
    }
    nodes[id].AddLeftChild(v[0]);
  }
  for (int i = 0; i < n; ++i) {
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, "
           "height = %d, %s\\n",
           i, nodes[i].GetParent(), nodes[i].GetSibling(nodes),
           nodes[i].GetDegree(nodes), nodes[i].CheckDepth(nodes),
           nodes[i].CheckHeight(nodes, nodes[i]),
           (nodes[i].GetParent() == NIL
                ? "root"
                : (nodes[i].GetLeftChild() == NIL ? "leaf" : "internal node")));
  }
  // system("pause");
  return 0;
}