提交时间:2024-01-21 18:57:34
运行 ID: 121441
#include<iostream> #include<cmath> using namespace std; struct Node{ int left,right; }s[1000005]; int ans; void dfs(int cur,int dep){ ans = max(ans,dep); if (s[cur].left){ dfs(s[cur].left,dep + 1); } if (s[cur].right){ dfs(s[cur].right,dep + 1); } } int main(){ int n; cin>>n; for (int i = 1;i <= n;i++){ cin>>s[i].left>>s[i].right; } dfs(1,1); cout<<ans<<endl; return 0; }