Pagini recente » Cod sursa (job #974736) | Cod sursa (job #2000974) | Autentificare | Cod sursa (job #573869) | Cod sursa (job #2783889)
#include <bits/stdc++.h>
#define nmax 100005
using namespace std;
ifstream in("darb.in");
ofstream out("darb.out");
vector<int> vec[nmax];
int maxx=1;
int maxdepth=0;
bool viz[nmax];
int dfs(int depth,int nod){
viz[nod]=1;
int maxxx=depth;
if(depth>maxdepth){maxx=nod;maxdepth=depth;}
for(auto i:vec[nod]){
if(!viz[i]){
maxxx=max(dfs(depth+1,i),maxxx);
}
}
return maxxx;
}
int main(){
int n;
in>>n;
int x,y;
for(int i=1;i<n;i++){
in>>x>>y;
vec[x].push_back(y);
vec[y].push_back(x);
}
dfs(1,maxx);
memset(viz,0,sizeof(viz));
out<<dfs(1,maxx);
}