Pagini recente » Cod sursa (job #1117427) | Cod sursa (job #149396) | Cod sursa (job #1463754) | Cod sursa (job #1996665) | Cod sursa (job #2592136)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("darb.in");
ofstream fout("darb.out");
const int VMAX = 100005;
int n, x, y, nivel_maxim, poz_nivel_max;
vector < int > graf[VMAX];
bitset < VMAX > viz;
void DFS(int nod, int nivel)
{
viz[nod] = 1;
if (nivel > nivel_maxim)
nivel_maxim = nivel, poz_nivel_max = nod;
for (unsigned int i = 0; i < graf[nod].size(); ++i)
if (!viz[graf[nod][i]]) DFS(graf[nod][i], nivel + 1);
}
int main()
{
fin >> n;
for (int i = 1; i < n; ++i)
{
fin >> x >> y;
graf[x].push_back(y);
graf[y].push_back(x);
}
DFS(1, 1);
viz.reset();
DFS(poz_nivel_max, 1);
fout << nivel_maxim;
}