Pagini recente » Cod sursa (job #574444) | Cod sursa (job #2720558) | Cod sursa (job #953630) | Cod sursa (job #2987098) | Cod sursa (job #2150007)
#include <bits/stdc++.h>
using namespace std;
ifstream f("darb.in");
ofstream g("darb.out");
const int nMax = 100005;
vector <int> G[nMax];
int dp[nMax], start;
inline void Dfs(int nod) {
if(dp[start] < dp[nod]){
start = nod;
}
for(const auto &v : G[nod]) {
if(!dp[v]) {
dp[v] = dp[nod] + 1;
Dfs(v);
}
}
}
int main()
{
int n, x, y;
f >> n;
for(int i = 1; i < n; i++) {
f >> x >> y;
G[x].push_back(y);
G[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;
}