Pagini recente » Cod sursa (job #2628001) | Cod sursa (job #627556) | Cod sursa (job #1920088) | Cod sursa (job #1249373) | Cod sursa (job #1112360)
#include <fstream>
#include <vector>
using namespace std;
const char InFile[]="darb.in";
const char OutFile[]="darb.out";
const int MaxN=100111;
ifstream fin(InFile);
ofstream fout(OutFile);
int N,x,y,sol,viz[MaxN],solnod,phase;
vector<int> G[MaxN];
void DFS(int nod, int d=1)
{
viz[nod]=phase;
for(vector<int>::iterator it=G[nod].begin();it!=G[nod].end();++it)
{
if(viz[*it]!=phase)
{
DFS(*it,d+1);
}
}
if(d>sol)
{
sol=d;
solnod=nod;
}
}
int main()
{
fin>>N;
for(register int i=1;i<N;++i)
{
fin>>x>>y;
G[x].push_back(y);
G[y].push_back(x);
}
fin.close();
++phase;
DFS(1);
++phase;
DFS(solnod);
fout<<sol;
fout.close();
return 0;
}