提交时间:2024-01-23 22:38:29

运行 ID: 125731

#include<bits/stdc++.h> using namespace std; int l[1000],r[1000],n; int depth(int i){ int a = 0,b = 0; if(l[i]){ a = depth(l[i]) + 1; } if(r[i]){ b = depth(r[i]) + 1; } return max(a,b); } int main(){ cin>>n; int i; for(i = 1;i <= n;i++)cin>>l[i]>>r[i]; cout<<depth(1) + 1; return 0; }