提交时间:2024-04-16 16:58:24

运行 ID: 143578

#include<bits/stdc++.h> using namespace std; int n,ans=-0x3f3f3f3f; struct node{ int left,right; }tree[1000005]; void dfs(int p,int deep){ if(p==0)return; ans=max(ans,deep); dfs(tree[p].left,deep+1); dfs(tree[p].right,deep+1); } int main(){ cin>> n; for(int i=1;i<=n;i++)cin>>tree[i].left>>tree[i].right; dfs(1,1); cout<<ans; return 0; }