#include <stdio.h>
#include <stdlib.h>
#define MAX 10000
#define NIL -1

int parent[MAX],left[MAX],right[MAX];
int n,D[MAX],H[MAX];

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

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