Pagini recente » Cod sursa (job #1915771) | Cod sursa (job #2381846) | Cod sursa (job #2141726) | Cod sursa (job #1379192) | Cod sursa (job #1997673)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream in("darb.in");
ofstream out("darb.out");
int n, maxdepth, v;
vector<int> g[100005];
void dfs(int x, int parent, int depth) {
if (depth > maxdepth) {
maxdepth = depth;
v = x;
}
for (int i = 0; i < g[x].size(); ++i) {
int y = g[x][i];
if (y == parent) continue;
dfs(y, x, depth + 1);
}
}
int main()
{
in >> n;
for (int i = 1, x, y; i < n; ++i) {
in >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
dfs(1, 1, 1);
dfs(v, v, 1);
out << maxdepth;
return 0;
}