Pagini recente » Cod sursa (job #698023) | Cod sursa (job #1792545) | Cod sursa (job #2608959) | Cod sursa (job #3155299) | Cod sursa (job #2570312)
#include<fstream>
#include<cstring>
#include<vector>
#include<stack>
using namespace std;
vector<int> g[100001];
bool vizitat[100001];
ifstream fin("darb.in");
ofstream fout("darb.out");
int n;
int xmax,dmax;
void citire() {
int i, x, y;
fin >> n ;
for (i = 1; i <= n-1; i++) {
fin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
}
void DFS(int x, int d)
{
int i,nod;
if(d>dmax)
{
xmax=x;
dmax=d;
}
vizitat[x]=true;
for(i=0;i<g[x].size();i++)
{
nod=g[x][i];
if(vizitat[nod]==false)
DFS(nod,d+1);
}
}
int main()
{
citire();
DFS(1,0);
//fout<<dmax<<' ';
dmax=0;
memset(vizitat,0,n);
DFS(xmax,1);
fout<<dmax;
}