Pagini recente » Cod sursa (job #2453280) | Cod sursa (job #591272) | Cod sursa (job #2441009) | Cod sursa (job #1780332) | Cod sursa (job #2762425)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("darb.in");
ofstream fout("darb.out");
const int MAXN = 1e5 + 2;
const int INF = 1e8 ;
vector <int> g[MAXN];
int depthmax, nodepth;
void lungime(int node, int depth, int papa){
if(depth > depthmax) {
depthmax = depth;
nodepth = node;
}
for(auto y : g[node]){
if(y != papa) lungime(y, depth + 1, node);
}
}
int main()
{
int n; fin >> n;
for(int i = 1; i <= n - 1; ++i){
int x, y; fin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
lungime(1, 0, 0);
lungime(nodepth, 0, 0);
fout << depthmax + 1;
return 0;
}