Pagini recente » Cod sursa (job #140240) | Cod sursa (job #2905472) | Cod sursa (job #2116529) | Cod sursa (job #1182882) | Cod sursa (job #1625999)
#include <iostream>
#include <stack>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
ifstream in("darb.in");
ofstream out("darb.out");
int n, T=1, dt=0, viz2[100001], i, x, y;
vector<int> viz, v[100001];
queue<int> Q;
void bfs(int x)
{
int K, G;
Q.push(x); viz[x]=1;
while(!Q.empty())
{
G=Q.front();
for(int i=0;i<v[G].size();i++)
{
K=v[G][i];
if(viz[K]==0)
{
viz[K] = viz[G] + 1;
T=viz[K];
Q.push(K);
}
}
Q.pop();
}
}
int main()
{
in>>n;
for(i=1;i<=n;i++)
{
in>>x>>y;
v[x].push_back(y);
v[y].push_back(x);
}
viz = vector<int> (n+1, 0);
bfs(1);
viz = vector<int> (n+1, 0);
dt=0;
bfs(T);
out<<T+1;
return 0;
}