https://www.luogu.com.cn/problem/P4913
#include<bits/stdc++.h>
using namespace std;
int n,ans=0;
struct node{
int l,r,id;
};
node tree[1000005];
void dfs(int p,int deep){
ans=max(ans,deep);
if(tree[p].l!=0)dfs(tree[p].l,deep+1);
if(tree[p].r!=0)dfs(tree[p].r,deep+1);
}
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>tree[i].l>>tree[i].r;
tree[i].id=i;
}
dfs(1,1);
cout<<ans;
return 0;
}