提交时间:2024-01-27 11:10:23

运行 ID: 129807

#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) + 1); return 0; }