Pagini recente » Istoria paginii runda/cocalari_danseaza_2014 | Statistici iancu mihai (dacic_frumushic) | template/meeting-under-construction | Istoria paginii utilizator/motociclentziu | Cod sursa (job #2655367)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("darb.in");
ofstream fout ("darb.out");
int n, x, y, radacina;
vector <int> V[100005];
int departe, lungime;
void fast ()
{
ios_base::sync_with_stdio(false);
cin.tie();
}
void dfs (int x, int tata, int nivel)
{
if (nivel>lungime)
{
lungime=nivel;
departe=x;
}
for (int i=0; i<(int)V[x].size(); i++)
{
int next = V[x][i];
if (next!=tata)
dfs (next, x, nivel+1);
}
}
int main()
{
fast();
fin >> n;
for (int i=1; i<=n-1; i++)
{
fin >> x >> y;
V[x].push_back(y);
V[y].push_back(x);
}
radacina=1;
dfs(radacina,0,1);
lungime=0;
dfs(departe,0,1);
fout << lungime;
return 0;
}