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