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

#include <cstdio>
#include <iostream>
using namespace std;

const int maxn = 10000 + 5;

struct Node {
  int father;
  int deep;
  int Child_number;
  int Height;
  int Left_Child, Right_Child;
  Node()
      : father(-1), deep(0), Child_number(0), Height(0), Left_Child(-1),
        Right_Child(-1) {}
} tree[maxn];

int n;

int max(int a, int b) { return a > b ? a : b; }

int solver(int node, int deep) {
  if (node == -1)
    return 0;
  tree[node].deep = deep;
  if (tree[node].Left_Child == -1 && tree[node].Right_Child == -1)
    return 0;
  int Left_Child = solver(tree[node].Left_Child, deep + 1);
  int Right_Child = solver(tree[node].Right_Child, deep + 1);
  if (tree[node].Left_Child != -1 && tree[node].Right_Child != -1)
    tree[node].Child_number = 2;
  else if (tree[node].Left_Child != -1 || tree[node].Right_Child != -1)
    tree[node].Child_number = 1;
  else
    tree[node].Child_number = 0;
  tree[node].Height = max(Left_Child + 1, Right_Child + 1);
  return tree[node].Height;
}

int Get_sibling(int node) {
  int father = tree[node].father;
  if (tree[father].Left_Child == node)
    return tree[father].Right_Child;
  else
    return tree[father].Left_Child;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int node;
    scanf("%d", &node);
    int Left_Child, Right_Child;
    scanf("%d%d", &Left_Child, &Right_Child);
    tree[Left_Child].father = node;
    tree[Right_Child].father = node;
    tree[node].Left_Child = Left_Child;
    tree[node].Right_Child = Right_Child;
  }
  int root;
  for (int i = 0; i < n; i++) {
    if (tree[i].father == -1) {
      root = i;
      break;
    }
  }
  /*printf("root = %d\\n",root);
  for(int i = 0;i < n; i++){
          printf("node %d: Left_Child = %d,Right_Child =
  %d\\n",i,tree[i].Left_Child,tree[i].Right_Child);
  }*/
  solver(root, 0);
  for (int i = 0; i < n; i++) {
    printf("node %d: ", i);
    printf("parent = %d, ", tree[i].father);
    if (i == root)
      printf("sibling = -1, ");
    else
      printf("sibling = %d, ", Get_sibling(i));
    printf("degree = %d, ", tree[i].Child_number);
    printf("depth = %d, ", tree[i].deep);
    printf("height = %d, ", tree[i].Height);
    if (i == root)
      printf("root\\n");
    else if (tree[i].Left_Child != -1 || tree[i].Right_Child != -1)
      printf("internal node\\n");
    else
      printf("leaf\\n");
  }
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;

const int maxn = 10000 + 5;

struct Node {
  int father;
  int deep;
  int Child_number;
  int Height;
  int Left_Child, Right_Child;
  Node()
      : father(-1), deep(0), Child_number(0), Height(0), Left_Child(-1),
        Right_Child(-1) {}
} tree[maxn];

int n;

int solver(int node, int deep) {
  tree[node].deep = deep;
  if (tree[node].Left_Child == -1 && tree[node].Right_Child == -1)
    return 0;
  int Left_Child = solver(tree[node].Left_Child, deep + 1);
  int Right_Child = solver(tree[node].Right_Child, deep + 1);
  if (tree[node].Left_Child != -1 && tree[node].Right_Child != -1)
    tree[node].Child_number = 2;
  else if (tree[node].Left_Child != -1 || tree[node].Right_Child != -1)
    tree[node].Child_number = 1;
  else
    tree[node].Child_number = 0;
  tree[node].Height = max(Left_Child + 1, Right_Child + 1);
  return tree[node].Height;
}

int Get_sibling(int node) {
  int father = tree[node].father;
  if (tree[father].Left_Child == node)
    return tree[father].Right_Child;
  else
    return tree[father].Left_Child;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int node;
    scanf("%d", &node);
    int Left_Child, Right_Child;
    scanf("%d%d", &Left_Child, &Right_Child);
    tree[Left_Child].father = node;
    tree[Right_Child].father = node;
    tree[node].Left_Child = Left_Child;
    tree[node].Right_Child = Right_Child;
  }
  int root;
  for (int i = 0; i < n; i++) {
    if (tree[i].father == -1) {
      root = i;
      break;
    }
  }
  /*printf("root = %d\\n",root);
  for(int i = 0;i < n; i++){
          printf("node %d: Left_Child = %d,Right_Child =
  %d\\n",i,tree[i].Left_Child,tree[i].Right_Child);
  }*/
  solver(root, 0);
  for (int i = 0; i < n; i++) {
    printf("node %d: ", i);
    printf("parent = %d, ", tree[i].father);
    if (i == root)
      printf("sibling = -1, ");
    else
      printf("sibling = %d, ", Get_sibling(i));
    printf("degree = %d, ", tree[i].Child_number);
    printf("depth = %d, ", tree[i].deep);
    printf("height = %d, ", tree[i].Height);
    if (i == root)
      printf("root\\n");
    else if (tree[i].Left_Child != -1 || tree[i].Right_Child != -1)
      printf("internal node\\n");
    else
      printf("leaf\\n");
  }
}