Pagini recente » Cod sursa (job #322712) | Cod sursa (job #3115) | Cod sursa (job #1877585) | Cod sursa (job #2079636) | Cod sursa (job #1367401)
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
const int maxn = 100005;
ifstream fin("darb.in");
ofstream fout("darb.out");
int n, dist[maxn], h;
vector <int> g[maxn];
inline void dfs(int node, int father) {
dist[node] = dist[father] + 1;
if(dist[h] < dist[node])
h = node;
for(auto it : g[node])
if(it != father)
dfs(it, node);
}
int main() {
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, 0);
dfs(h, 0);
fout << dist[h] << '\n';
}