提交时间:2023-08-23 16:39:53

运行 ID: 99738

#include <iostream> using namespace std; #define int long long struct{ int f,c1,c2,d; }a[10005]; signed main(){ for (int i = 0;i<1005;i++) a[i].f=a[i].c1=a[i].c2=a[i].d=1; 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==y&&x==0) continue; a[i].c1=x,a[i].c2=y; a[x].f=a[y].f=i; a[x].d=a[y].d=a[i].d+1; maxn = max(maxn,a[i].d+1); } cout << maxn; }