1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 const int N = 1e6 + 10; 6 7 int ok = 0; 8 9 int n; 10 struct node 11 { 12 int l, r; 13 } t[N]; 14 15 void dfs(int i, int s) 16 { 17 if(i == 0) return; 18 ok = max(ok, s); 19 dfs(t[i].l, s + 1); 20 dfs(t[i].r, s + 1); 21 } 22 signed main() 23 { 24 scanf("%d", &n); 25 for(int i = 1; i <= n; ++i) scanf("%d%d", &t[i].l, &t[i].r); 26 dfs(1, 1); 27 28 printf("%d", ok); 29 30 return 0; 31 }