Pagini recente » Cod sursa (job #3255633) | Cod sursa (job #2636189) | Cod sursa (job #316554) | Cod sursa (job #2986658) | Cod sursa (job #3155745)
#include <bits/stdc++.h>
using ll=long long;
#define S second
#define F first
#define endl '\n'
#define spid ios_base::sync_with_stdio(false);cin.tie(NULL);
const int mod=1e9+7;
const double pi=3.14159265359;
const int maxn=100001;
using namespace std;
int n,depth[maxn];
vector<vector<int>> G(maxn,vector<int>());
void dfs(int i,int parent){
for(int j=0;j<G[i].size();j++){
if(G[i][j]!=parent){
depth[G[i][j]]=depth[i]+1;
dfs(G[i][j],i);
}
}
}
int main(){
ifstream cin("darb.in");
ofstream cout("darb.out");
cin>>n;
for(int i=0;i<n-1;i++){
int a,b;
cin>>a>>b;
G[a-1].push_back(b-1);
G[b-1].push_back(a-1);
}
dfs(0,-1);
int nod,maxdist=0;
for(int i=0;i<n;i++){
if(depth[i]>maxdist){
maxdist=depth[i];
nod=i;
}
}
depth[nod]=0;
dfs(nod,-1);
maxdist=0;
for(int i=0;i<n;i++){
maxdist=max(maxdist,depth[i]);
}
cout<<maxdist+1<<endl;
}