#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=1e6+10;
struct node
{
int fa,ch[2],deep;
};
int n,res;
node tree[N];
void get(int u,int dep)
{
if(u==0)
return;
tree[u].deep=dep;
res=max(res,dep);
get(tree[u].ch[0],dep+1);
get(tree[u].ch[1],dep+1);
return;
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
int a,b;
cin>>a>>b;
tree[i].ch[0]=a;
tree[i].ch[1]=b;
if(a)
tree[a].fa=i;
if(b)
tree[b].fa=i;
}
get(1,1);
cout<<res<<endl;
return 0;
}
全部回复 共 0 条
还没有人回复。往下写第一条。
发表回复
登录后即可回复本帖,与出题人和同学一起讨论。
登录