Pagini recente » Monitorul de evaluare | Profil valentino | Profil UAIC_ChiliGrozaVartolomei | ONIS 2015, Clasament Runda 3 | Cod sursa (job #2562783)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("darb.in");
ofstream fout("darb.out");
int viz[100005];
int maxim,maximus;
vector<int> G[100005];
void dfs(int nod,int t,int h){
int i;
viz[nod] = t;
for(auto vecin: G[nod]){
if(viz[vecin] != t){
dfs(vecin,t,h+1);
}
}
if(maxim < h){
maximus = nod;
maxim = h;
}
}
int main(){
int n,i,a,b;
fin>>n;
for(i = 1; i < n; i++){
fin>>a>>b;
G[a].push_back(b);
G[b].push_back(a);
}
dfs(1,1,0);
dfs(maximus,2,1);
fout<<maxim<<'\n';
return 0;
}