Pagini recente » Cod sursa (job #2923875) | Cod sursa (job #1399142) | Cod sursa (job #2229644) | Cod sursa (job #346873) | Cod sursa (job #2558171)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("darb.in");
ofstream fout("darb.out");
const int MAXN = 1 * 1e5 + 5;
vector <int> g[MAXN];
int depthmax, indice;
bool seen[MAXN];
void dfs(int node, int depth){
if(seen[node]) return ;
seen[node] = true;
if(depth > depthmax) {
depthmax = depth;
indice = node;
}
for(auto x : g[node]) {
if(!seen[x] ) dfs(x, depth + 1);
}
}
int main()
{
int n; fin >> n;
for(int i = 1; i < n; ++i){
int x, y; fin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
dfs(1, 1);
for(int i = 1; i <= n; ++i) seen[i] = false;
dfs(indice, 1);
fout << depthmax;
return 0;
}