Pagini recente » Cod sursa (job #1939315) | Cod sursa (job #345803) | Cod sursa (job #2161481) | Cod sursa (job #2027125) | Cod sursa (job #2204999)
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
ifstream f("darb.in");
ofstream g("darb.out");
vector<int> v[100001];
int N, nodmax;
bool viz[100001];
int lg[100001];
queue<int> Coada;
void BFS(int x)
{
Coada.push(x);
viz[x] = 1;
while(!Coada.empty())
{
int crt = Coada.front();
Coada.pop();
for(auto &it : v[crt])
if(viz[it] == 0)
{
Coada.push(it);
viz[it] = 1;
lg[it] = 1 + lg[crt];
nodmax = it;
}
}
}
int main()
{
int x, y;
f >> N;
for(int i = 1; i < N; i++)
{
f >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
BFS(1);
for(int i = 1; i <= N; i++)
viz[i] = 0,lg[i]=1;
BFS(nodmax);
g << lg[nodmax];
return 0;
}