Pagini recente » Cod sursa (job #2602538) | Cod sursa (job #2772745) | Cod sursa (job #2748407) | Cod sursa (job #3194187) | Cod sursa (job #2393416)
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 15;
vector <int> g[MAXN];
int depthmax, best;
void parcurgere(int node, int papa, int depth){
if(depth > depthmax){
best = node;
depthmax = depth;
}
for(auto y : g[node] )
if(y != papa)
parcurgere(y, node, depth + 1);
}
ifstream fin("darb.in");
ofstream fout("darb.out");
int main(){
int n;
fin >> n ;
for(int i = 1; i <= n - 1; ++i){
int a, b;
fin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
parcurgere(1, 0, 0);
int leaf = best;
best = 0;
depthmax = 0;
parcurgere(leaf, 0, 0);
fout << depthmax + 1;
return 0;
}