提交时间:2023-08-23 16:11:21

运行 ID: 99711

#include<bits/stdc++.h> using namespace std; int a[10000],ma; int main(){ int n; cin>>n; a[1]=1; for(int i=1;i<=n;i++){ int x,y,m; cin>>x>>y; if(x==0&&y==0) continue; if(x==0){ a[x]=a[i]+1; m=a[x]; if(i==1||ma<m) ma=m; continue; } if(y==0){ a[y]=a[i]+1; m=a[y]; if(i==1||ma<m) ma=m; continue; } a[x]=a[i]+1; a[y]=a[i]+1; } cout<<ma; }