Language: C++

int height(NODE *, int);

int main(){

  int i, j;
  int n, set;
  NODE a[N];
  
  scanf("%d", &n);
  
  for(i = 0; i < n; i++){
    scanf("%d%d%d", &a[i].id, &a[i].left, &a[i].right);
    
  }
  
  tmpa(a, n);
  parent(a, n);

  for(i = 0; i < n; i++){
    if(a[i].parent == -1){
      a[i].depth = 0;
      set = i;
    }
  }

  depth(a, set);

  for(i = 0; i < n; i++){
    a[i].height = height(a, a[i].id);
  }  

  for(i = 0; i < n; i++){
    printf("node %d: parent = %d, sibling = %d, ", a[i].id, a[i].parent, a[i].sibling);
    printf("degree = %d, depth = %d, height = %d, ", a[i].degree, a[i].depth, a[i].height);
    if(a[i].parent == -1) printf("root\n");
    else if(a[i].degree > 0) printf("internal node\n");
    else printf("leaf\n");

  }  

  return 0;
}

void tmpa(NODE *a, int n){

  int i, j;
  NODE tmp;
  
  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      if(a[j].id != j){
	tmp = a[a[j].id];
	a[a[j].id] = a[j];
	a[j] = tmp;
      }
    
    }
  }  

}

void parent(NODE *a, int n){

  int i;

  for(i = 0; i < n; i++){
    a[i].parent = -1;
    a[i].sibling = -1;
    a[i].degree = 0;
    if(a[i].right != -1) a[i].degree++;
    if(a[i].left != -1) a[i].degree++;
  }

  for(i = 0; i < n; i++){
    
    if(a[i].right != -1){
      a[a[i].right].parent = a[i].id;
      a[a[i].right].sibling = a[i].left;

    }

    if(a[i].left != -1){
      a[a[i].left].parent = a[i].id;
      a[a[i].left].sibling = a[i].right;

    }

  }

}

void depth(NODE *a, int n){

  if(a[n].right != -1){
    a[a[n].right].depth = a[n].depth + 1;
    depth(a, a[n].right);
    
  }
   
  if(a[n].left != -1){
    a[a[n].left].depth = a[n].depth + 1;
    depth(a, a[n].left);
    
  }
 
}

int height(NODE *a, int n){

  int r = 1, l = 1;

  if(a[n].right == -1 && a[n].left == -1) return 0;

  if(a[n].right != -1){
    r += height(a, a[n].right);
  }
  
  if(a[n].left != -1){
    l += height(a, a[n].left);
  }
  
  if(r >= l) return r;
  else return l;

}

Compiler output:
a.cc:1:12: error: 'NODE' was not declared in this scope
    1 | int height(NODE *, int);
      |            ^~~~
a.cc:1:18: error: expected primary-expression before ',' token
    1 | int height(NODE *, int);
      |                  ^
a.cc:1:20: error: expected primary-expression before 'int'
    1 | int height(NODE *, int);
      |                    ^~~
a.cc:1:23: error: expression list treated as compound expression in initializer [-fpermissive]
    1 | int height(NODE *, int);
      |                       ^
a.cc: In function 'int main()':
a.cc:7:3: error: 'NODE' was not declared in this scope
    7 |   NODE a[N];
      |   ^~~~
a.cc:9:3: error: 'scanf' was not declared in this scope
    9 |   scanf("%d", &n);
      |   ^~~~~
a.cc:12:22: error: 'a' was not declared in this scope
   12 |     scanf("%d%d%d", &a[i].id, &a[i].left, &a[i].right);
      |                      ^
a.cc:16:8: error: 'a' was not declared in this scope
   16 |   tmpa(a, n);
      |        ^
a.cc:16:3: error: 'tmpa' was not declared in this scope
   16 |   tmpa(a, n);
      |   ^~~~
a.cc:17:3: error: 'parent' was not declared in this scope
   17 |   parent(a, n);
      |   ^~~~~~
a.cc:26:3: error: 'depth' was not declared in this scope
   26 |   depth(a, set);
      |   ^~~~~
a.cc:29:36: error: 'height' cannot be used as a function
   29 |     a[i].height = height(a, a[i].id);
      |                                    ^
a.cc:33:5: error: 'printf' was not declared in this scope
   33 |     printf("node %d: parent = %d, sibling = %d, ", a[i].id, a[i].parent, a[i].sibling);
      |     ^~~~~~
a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 | int height(NODE *, int);
a.cc: At global scope:
a.cc:44:6: error: variable or field 'tmpa' declared void
   44 | void tmpa(NODE *a, int n){
      |      ^~~~
a.cc:44:11: error: 'NODE' was not declared in this scope
   44 | void tmpa(NODE *a, int n){
      |           ^~~~
a.cc:44:17: error: 'a' was not declared in this scope
   44 | void tmpa(NODE *a, int n){
      |                 ^
a.cc:44:20: error: expected primary-expression before 'int'
   44 | void tmpa(NODE *a, int n){
      |                    ^~~
a.cc:62:6: error: variable or field 'parent' declared void
   62 | void parent(NODE *a, int n){
      |      ^~~~~~
a.cc:62:13: error: 'NODE' was not declared in this scope
   62 | void parent(NODE *a, int n){
      |             ^~~~
a.cc:62:19: error: 'a' was not declared in this scope
   62 | void parent(NODE *a, int n){
      |                   ^
a.cc:62:22: error: expected primary-expression before 'int'
   62 | void parent(NODE *a, int n){
      |                      ^~~
a.cc:92:6: error: variable or field 'depth' declared void
   92 | void depth(NODE *a, int n){
      |      ^~~~~
a.cc:92:12: error: 'NODE' was not declared in this scope
   92 | void depth(NODE *a, int n){
      |            ^~~~
a.cc:92:18: error: 'a' was not declared in this scope
   92 | void depth(NODE *a, int n){
      |                  ^
a.cc:92:21: error: expected primary-expression before 'int'
   92 | void depth(NODE *a, int n){
      |                     ^~~
a.cc:108:5: error: redefinition of 'int height'
  108 | int height(NODE *a, int n){
      |     ^~~~~~
a.cc:1:5: note: 'int height' previously defined here
    1 | int height(NODE *, int);
      |     ^~~~~~
a.cc:108:12: error: 'NODE' was not declared in this scope
  108 | int height(NODE *a, int n){
      |            ^~~~
a.cc:108:18: error: 'a' was not declared in this scope
  108 | int height(NODE *a, int n){
      |                  ^
a.cc:108:21: error: expected primary-expression before 'int'
  108 | int height(NODE *a, int n){
      |                     ^~~