Pagini recente » Cod sursa (job #2259645) | Cod sursa (job #1883187) | Cod sursa (job #3192473) | Cod sursa (job #2196039) | Cod sursa (job #3286632)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("darb.in");
ofstream fout("darb.out");
int n, maxx, nod;
bitset <100003> viz;
vector <int> g[100003];
void DFS(int x, int cnt)
{
viz[x] = 1;
for (int i : g[x])
if (viz[i] == 0) DFS(i, cnt + 1);
if (maxx < cnt)
{
maxx = cnt;
nod = x;
}
}
int main()
{
int i, j, p;
fin >> n;
for (p = 1; p < n; p++)
{
fin >> i >> j;
g[i].push_back(j);
g[j].push_back(i);
}
DFS(1, 0);
for (i = 1; i <= n; i++)
viz[i] = 0;
DFS(nod, 1);
fout << maxx<< "\n";
return 0;
}
//0, 1, 3-5, 7-18, 21, 22, 24-27, 29, 30, 34-36, 42, 44, 45, 47, 48, 51, 54, 56-58