#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#define maxn 100005
#define INF 0x3fffffff
using namespace std;
vector<int> h[maxn];
int son[maxn];
int n,ans;
int dfs(int u,int pre){
int fir=0,sec=0;
if(h[u].size()==0) return 1;
if(son[u]>0) return son[u];
for(int i=0;i<h[u].size();i++){
int v=h[u][i];
int t=dfs(v,pre+1);
if(t>=fir){
sec=fir;
fir=t;
}
else if(t>sec){
sec=t;
}
}
son[u]=fir+1;
ans=max(ans,fir+pre+sec);
return son[u];
}
int main(){
int u,v;
while(~scanf("%d",&n)){
ans=0;
memset(h,0,sizeof(h));
memset(son,0,sizeof(son));
for(int i=1;i<n;i++){
scanf("%d%d",&u,&v);
h[u].push_back(v);
}
dfs(1,0);
printf("%d\n",ans);
}
return 0;
}
hihoCoder挑战赛14 B 赛车
最新推荐文章于 2024-06-15 17:16:12 发布