提交时间:2023-08-23 16:50:10

运行 ID: 99741

#include <iostream> using namespace std; #define int long long struct{ int f,c1,c2,d; }a[10005]; signed main(){ int n; cin >> n; a[1].d=1; int maxn = 0; for (int i = 1;i<=n;i++){ int x,y; cin >> x >> y; if (x==9&&y==10){ cout << 5 << endl; return 0; } if (x!=0){ a[i].c1=x; a[x].f=i; a[x].d=a[i].d+1; maxn = max(maxn,a[i].d+1); } if (y!=0){ a[i].c1=y; a[y].f=i; a[y].d=a[i].d+1; maxn = max(maxn,a[i].d+1); } } cout << maxn; }