提交时间:2024-01-22 14:40:49

运行 ID: 122218

#include <bits/stdc++.h> using namespace std; int n,L[110],R[110]; int DFS(int i) { int l = 0,r = 0; if(L[i]) l = DFS(L[i]) + 1; if(R[i]) r = DFS(R[i]) + 1; return max(l,r); } int main() { scanf("%d",&n); for(int i = 1;i <= n;i++) scanf("%d%d",&L[i],&R[i]); printf("%d\n",DFS(1)); return 0; }