Pagini recente » Cod sursa (job #722339) | Cod sursa (job #1315197) | Cod sursa (job #713918) | Cod sursa (job #2988548) | Cod sursa (job #3293745)
// darb.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
ifstream cin("darb.in");
ofstream cout("darb.out");
int n, x, y, nivel[100001], ma, P;
vector<int> G[100001];
bool v[100001];
void dfs(int x, int h) {
if (!v[x]) {
nivel[x] = h;
v[x] = 1;
if (h > ma) {
P = x; ma = h;
}
for (int i : G[x])
dfs(i, h + 1);
}
}
int main()
{
cin >> n;
for (int i = 1; i < n; i++)
{
cin >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
dfs(1, 0);
fill(v + 1, v + 1 + n, 0);
fill(nivel + 1, nivel + 1 + n, 0);
ma = 0;
dfs(P, 0);
cout << ma + 1;
}