Pagini recente » Cod sursa (job #2971255) | Cod sursa (job #859685) | Cod sursa (job #581151) | Cod sursa (job #3130240) | Cod sursa (job #2815409)
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
ifstream in("darb.in");
ofstream out("darb.out");
vector<int> l[100005];
int vizitat[100005];
int n;
int nivelMaxim, pozitieNivel; //nivMaxim - nr de noduri dintre 2 frunz
void dfs_arb(int nod, int nivel)
{
vizitat[nod] = 1;
if(nivel >= nivelMaxim)
{
nivelMaxim=nivel;
pozitieNivel=nod;
}
for(auto el:l[nod])
{
if(vizitat[el]==0)
{
dfs_arb(el,nivel+1);
}
}
}
void afisare_darb()
{
int x,y;
in>>n;
for(int i=0;i<n;++i)
{
in>>x>>y;
l[x].push_back(y);
l[y].push_back(x);
}
dfs_arb(1,0);
for(int i = 0; i<n; ++i)
{
vizitat[i]=0;
}
dfs_arb(pozitieNivel, 0);
out<<nivelMaxim+1;
}
int main()
{
afisare_darb();
return 0;
}