Pagini recente » Cod sursa (job #2636383) | Cod sursa (job #51234) | Cod sursa (job #687701) | Cod sursa (job #1086694) | Cod sursa (job #2629479)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream in("darb.in");
ofstream out("darb.out");
vector <int> v[100001];
bool viz[100001];
int n, yy, xx, nodmax, maxdepth, depth;
void readit()
{
in>>n;
for(int i=1; i<n; i++) in>>yy>>xx, v[yy].push_back(xx), v[xx].push_back(yy);
}
void DFS(int nod)
{
viz[nod]=1;
++depth;
for(int i=0; i<v[nod].size(); i++)
if(!viz[v[nod][i]]) DFS(v[nod][i]);
if(depth>maxdepth) maxdepth=depth, nodmax=nod;
--depth;
}
void clearvec()
{
for(int i=1; i<=n; i++) viz[i]=0;
}
int main()
{
readit();
DFS(1);
clearvec();
DFS(nodmax);
out<<maxdepth;
return 0;
}