Pagini recente » Cod sursa (job #1686992) | Cod sursa (job #338541) | Cod sursa (job #1352153) | Cod sursa (job #1833035) | Cod sursa (job #2049159)
/**
*/
#include<iostream>
#include<fstream>
#include<string.h>
#include<queue>
#include<vector>
using namespace std;
vector <int>G[100001];
queue <int>Q;
ifstream fin;
ofstream fout("darb.out");
int N,d[100001];
void Read()
{
fin.open("darb.in");
fin>>N;
for(int i=1;i<N;i++)
{
int x,y;
fin>>x>>y;
G[x].push_back(y);
G[y].push_back(x);
}
}
void bfs(int nod)
{
Q.push(nod);
for(int i=1;i<=N;i++)
d[i]=-1;
d[nod]=0;
while(!Q.empty())
{
int Nod;
Nod=Q.front();Q.pop();
for(int i=0;i<(int)G[Nod].size();i++)
{
if(d[G[Nod][i]]==-1)
{
d[G[Nod][i]]=d[Nod]+1;
Q.push(G[Nod][i]);
}
}
}
}
int main()
{
int maxim=0,imax;
Read();
bfs(1);
for(int i=1;i<=N;i++)
if(d[i]>maxim){imax=i;maxim=d[i];}
bfs(imax);
for(int i=1;i<=N;i++)
if(d[i]>maxim){maxim=d[i];}
fout<<maxim+1;
return 0;
}