Pagini recente » Cod sursa (job #1570892) | Cod sursa (job #637064) | Cod sursa (job #1657048) | Cod sursa (job #1392950) | Cod sursa (job #1130664)
/*
Keep It Simple!
*/
#include<stdio.h>
#include<list>
#include<string.h>
using namespace std;
#define Max(a,b) (a>b?a:b)
int n,dist[100005],Vmax,pos;
list<int> G[100005];
void DFS(int node)
{
for(list<int>::iterator it = G[node].begin(); it!=G[node].end(); it++)
if(!dist[*it])
{
dist[*it] = dist[node]+1;
if(dist[*it]>Vmax)
{
Vmax = dist[*it];
pos = *it;
}
DFS(*it);
}
}
int main()
{
freopen("darb.in","r",stdin);
freopen("darb.out","w",stdout);
scanf("%d",&n);
int x,y;
for(int i=1;i<=n;i++)
{
scanf("%d%d",&x,&y);
G[x].push_back(y);
G[y].push_back(x);
}
DFS(1);
memset(dist,0,(n+2)*4);
Vmax = 0;
DFS(pos);
printf("%d",Vmax+1);
}