Pagini recente » Cod sursa (job #1310749) | Cod sursa (job #997736) | Clasament 123abcz | Cod sursa (job #2388680) | Cod sursa (job #2204280)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("darb.in");
ofstream g("darb.out");
const int NMAX = 100001;
int N, dist, ult;
bool viz[NMAX];
vector<int> lista[NMAX];
void DFS(int x, int niv)
{
if(niv > dist)
{
dist = niv;
ult = x;
}
viz[x] = true;
for(auto &it : lista[x])
if(viz[it] == false)
DFS(it, niv + 1);
}
int main()
{
int x, y;
f >> N;
for(int i = 1; i < N; i++)
{
f >> x >> y;
lista[x].push_back(y);
lista[y].push_back(x);
}
DFS(1, 1);
dist = 0;
for(int i = 1; i <= N; i++)
viz[i] = false;
DFS(ult, 1);
g << dist;
return 0;
}