Pagini recente » Cod sursa (job #501662) | Cod sursa (job #430783) | Cod sursa (job #2763131) | Cod sursa (job #655753) | Cod sursa (job #1827790)
#include <bits/stdc++.h>
using namespace std;
ifstream f("darb.in");
ofstream g("darb.out");
const int nMax = 100002;
vector <int> Tree[nMax];
int dp[nMax], start;
inline void Dfs(int nod) {
if(dp[nod] > dp[start]) {
start = nod;
}
for(auto i : Tree[nod]) {
if(!dp[i]) {
dp[i] = dp[nod] + 1;
Dfs(i);
}
}
}
int main()
{
int n, x, y;
f >> n;
for(int i = 1; i < n; i++) {
f >> x >> y;
Tree[x].push_back(y);
Tree[y].push_back(x);
}
dp[1] = 1;
Dfs(1);
for(int i = 1; i <= n; i++) {
dp[i] = 0;
}
dp[start] = 1;
Dfs(start);
g<< dp[start] << "\n";
return 0;
}