Pagini recente » Cod sursa (job #161573) | Cod sursa (job #868629) | Istoria paginii runda/forsen/clasament | Istoria paginii runda/concurs_11_12_02_26/clasament | Cod sursa (job #2432430)
#include <bits/stdc++.h>
using namespace std;
ifstream in("darb.in");
ofstream out("darb.out");
const int DIM = 1e5 + 7;
vector <int> v[DIM];
int d[DIM];
bitset <DIM> vis;
queue <int> q;
main()
{
int n;
in >> n;
for(int i = 1; i < n; i++)
{
int x, y;
in >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
int last = 1;
q.push(1);
vis[1] = true;
while(!q.empty())
{
int nod = q.front();
q.pop();
last = nod;
for(auto i : v[nod])
if(vis[i] == false)
{
vis[i] = true;
q.push(i);
}
}
int mx = 0;
vis[last] = false;
q.push(last);
while(!q.empty())
{
int nod = q.front();
q.pop();
mx = max(mx, d[nod]);
for(auto i : v[nod])
if(vis[i] == true)
{
vis[i] = false;
q.push(i);
d[i] = d[nod] + 1;
}
}
out << mx + 1;
}