Language: C++

#include<cstdio>
#define MAX 10000
#define NIL -1

struct Node{ int parent,left,right;};

Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u,int d){
if(u==NIL) return;
D[u]=d;
setDepth(T[u].left,d+1);
setDepth(T[u].right,d+1);
}

int setHeight(int u){
int h1=0,h2=0;
if(T[u].left!=NIL)
h1=setHeight(T[u].left)+1;#include<cstdio>
using namespace std;
#define MAX 10000
#define NIL -1

struct Node{ int parent,left,right;};

Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u,int d){
if(u==NIL) return;
D[u]=d;
setDepth(T[u].left,d+1);
setDepth(T[u].right,d+1);
}

int setHeight(int u){
int h1=0,h2=0;
if(T[u].left!=NIL)
h1=setHeight(T[u].left)+1;
if(T[u].right!=NIL)
h2=setHeight(T[u].right)+1;
return H[u]=(h1>h2 ? h1:h2);
}


int getSibling(int u){
if(T[u].parent==NIL) return NIL;
if(T[T[u].parent].left!=u&&T[T[u].parent].left!=NIL) 
return T[T[u].parent].left;
if(T[T[u].parent].right!=u&&T[T[u].parent].right!=NIL) 
return T[T[u].parent].right;
return NIL;
}

void print(int u){
printf("node %d:",u);
printf("parent=%d,",T[u].parent);
printf("sibling=%d,",getSibling(u));
int deg=0;
if(T[u].left!=NIL) deg++;
if(T[u].right!=NIL) deg++;
printf("degree=%d,",deg);
printf("depth=%d,",D[u]);
printf("height=%d,",H[u]);

if(T[u].parent==NIL){
printf("root\n");
} else if(T[u].left==NIL&&T[u].right==NIL){
printf("leaf\n");
} else{
printf("internal node\n");
}
}

int main(){
int v,l,r,root=0;
scanf("%d",&n);

for(int i=0;i<n;i++) T[i].parent=NIL;

for(int i=0;i<n;i++){
scanf("%d %d %d",&v,&l,&r);
T[v].left=l;
T[v].right=r;
if(l!=NIL) T[l].parent=v;
if(r!=NIL) T[r].parent=v;
}

for(int i=0;i<n;i++) if(T[i].parent==NIL) root=i;

setDepth(root,0);
setHeight(root);

for(int i=0;i<n;i++) print(i);

return 0;
}
if(T[u].right!=NIL)
h2=setHeight(T[u].right)+1;
return H[u]=(h1>h2 ? h1:h2);
}


int getSibling(int u){#include <cstdio>

using namespace std;

#define MAX 10000
#define NIL -1

struct Node { int parent, left, right;};

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u,int d) {
	if(u == NIL) return;
	D[u] = d;
	setDepth(T[u].left, d+1);
	setDepth(T[u].right,d+1);
}

int setHeight(int u) {
	int h1 = 0, h2 = 0;
	if(T[u].left != NIL)
		h1 = setHeight(T[u].left)  + 1;
	if(T[u].right != NIL)
		h2 = setHeight(T[u].right) + 1;
	return H[u] = (h1 > h2 ? h1 : h2);
}


int getSibling(int u) {
	if( T[u].parent == NIL ) return NIL;
	if(T[T[u].parent].left != u && T[T[u].parent].left != NIL )
		return T[T[u].parent].left;
	if(T[T[u].parent].right != u && T[T[u].parent].right != NIL )
		return T[T[u].parent].right;
	return NIL;
}

void print(int u) {
	printf("node %d: ",u);
	printf("parent = %d, ",T[u].parent);
	printf("sibling = %d, ",getSibling(u));
	int deg = 0;
	if(T[u].left  != NIL) deg++;
	if(T[u].right != NIL) deg++;
	printf("degree = %d, ",deg);
	printf("depth = %d, ",D[u]);
	printf("height = %d, ",H[u]);
	
	if(T[u].parent == NIL) {
		printf("root\n");
	} else if(T[u].left == NIL && T[u].right == NIL) {
		printf("leaf\n");
	} else {
		printf("internal node\n");
	}
}

int main(void) {
	int v, l, r, root = 0;
	scanf("%d",&n);
	for(int i=0;i<n;i++) T[i].parent = NIL;
	for(int i=0;i<n;i++) {
		scanf("%d %d %d",&v,&l,&r);
		T[v].left  = l;
		T[v].right = r;
		if(l != NIL) T[l].parent = v;
		if(r != NIL) T[r].parent = v;
	}
	
	for(int i=0; i<n; i++)
	if(T[i].parent == NIL) root = i;
	
	setDepth(root,0);
	setHeight(root);
	
	for(int i=0;i<n;i++) print(i);
	
	return 0;
}

if(T[u].parent==NIL) return NIL;
if(T[T[u].parent].left!=u&&T[T[u].parent].left!=NIL) 
return T[T[u].parent].left;
if(T[T[u].parent].right!=u&&T[T[u].parent].right!=NIL) 
return T[T[u].parent].right;
return NIL;
}

void print(int u){
printf("node %d:",u);
printf("parent=%d,",T[u].parent);
printf("sibling=%d,",getSibling(u));
int deg=0;
if(T[u].left!=NIL) deg++;
if(T[u].right!=NIL) deg++;
printf("degree=%d,",deg);
printf("depth=%d,",D[u]);
printf("height=%d,",H[u]);

if(T[u].parent==NIL){
printf("root\n");
} else if(T[u].left==NIL&&T[u].right==NIL){
printf("leaf\n");
} else{
printf("internal node\n");
}
}

int main(){
int v,l,r,root=0;
scanf("%d",&n);

for(int i=0;i<n;i++) T[i].parent=NIL;

for(int i=0;i<n;i++){
scanf("%d %d %d",&v,&l,&r);
T[v].left=l;
T[v].right=r;
if(l!=NIL) T[l].parent=v;
if(r!=NIL) T[r].parent=v;
}

for(int i=0;i<n;i++) if(T[i].parent==NIL) root=i;

setDepth(root,0);
setHeight(root);

for(int i=0;i<n;i++) print(i);

return 0;
}


Compiler output:
a.cc:20:27: error: stray '#' in program
   20 | h1=setHeight(T[u].left)+1;#include<cstdio>
      |                           ^
a.cc:105:23: error: stray '#' in program
  105 | int getSibling(int u){#include <cstdio>
      |                       ^
a.cc: In function 'int setHeight(int)':
a.cc:20:28: error: 'include' was not declared in this scope
   20 | h1=setHeight(T[u].left)+1;#include<cstdio>
      |                            ^~~~~~~
a.cc:20:36: error: 'cstdio' was not declared in this scope; did you mean 'stdin'?
   20 | h1=setHeight(T[u].left)+1;#include<cstdio>
      |                                    ^~~~~~
      |                                    stdin
a.cc:21:1: error: expected primary-expression before 'using'
   21 | using namespace std;
      | ^~~~~
a.cc:30:27: error: a function-definition is not allowed here before '{' token
   30 | void setDepth(int u,int d){
      |                           ^
a.cc:37:21: error: a function-definition is not allowed here before '{' token
   37 | int setHeight(int u){
      |                     ^
a.cc:47:22: error: a function-definition is not allowed here before '{' token
   47 | int getSibling(int u){
      |                      ^
a.cc:56:18: error: a function-definition is not allowed here before '{' token
   56 | void print(int u){
      |                  ^
a.cc:76:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   76 | int main(){
      |         ^~
a.cc:76:9: note: remove parentheses to default-initialize a variable
   76 | int main(){
      |         ^~
      |         --
a.cc:76:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:76:11: error: a function-definition is not allowed here before '{' token
   76 | int main(){
      |           ^
a.cc: In function 'int getSibling(int)':
a.cc:105:24: error: 'include' was not declared in this scope
  105 | int getSibling(int u){#include <cstdio>
      |                        ^~~~~~~
a.cc:105:33: error: 'cstdio' was not declared in this scope; did you mean 'stdin'?
  105 | int getSibling(int u){#include <cstdio>
      |                                 ^~~~~~
      |                                 stdin
a.cc:107:1: error: expected primary-expression before 'using'
  107 | using namespace std;
      | ^~~~~
a.cc:117:28: error: a function-definition is not allowed here before '{' token
  117 | void setDepth(int u,int d) {
      |                            ^
a.cc:124:22: error: a function-definition is not allowed here before '{' token
  124 | int setHeight(int u) {
      |                      ^
a.cc:134:23: error: a function-definition is not allowed here before '{' token
  134 | int getSibling(int u) {
      |                       ^
a.cc:143:19: error: a function-definition is not allowed here before '{' token
  143 | void print(int u) {
      |                   ^
a.cc:163:16: error: a function-definition is not allowed here before '{' token
  163 | int main(void) {
      |                ^