Pagini recente » Cod sursa (job #2636482) | Cod sursa (job #340535) | Cod sursa (job #1497534) | Cod sursa (job #77722) | Cod sursa (job #1106308)
#include<fstream>
#include<vector>
#include<cstring>
using namespace std;
ifstream eu("darb.in");
ofstream tu("darb.out");
#define Nmax 100005
int N,Sol,SolN;
vector<int>G[Nmax];
bool Use[Nmax];
void DFS(int nod,int lvl)
{
if(lvl>Sol)
{
Sol=lvl;
SolN=nod;
}
Use[nod]=1;
for(vector<int>:: iterator it=G[nod].begin();it!=G[nod].end();it++)
{
if(!Use[*it])
DFS(*it,lvl+1);
}
}
int main()
{
eu>>N;
while(N--)
{
int x,y;
eu>>x>>y;
G[x].push_back(y);
G[y].push_back(x);
}
DFS(1,0);
Sol=0;
memset(Use,0,Nmax);
DFS(SolN,0);
tu<<Sol+1<<"\n";
return 0;
}