Pagini recente » Cod sursa (job #2090656) | Cod sursa (job #80844) | Cod sursa (job #589833) | Cod sursa (job #1526537) | Cod sursa (job #1488849)
#include <fstream>
#include <vector>
#include <queue>
#include <cstring>
int d[100001];
using namespace std;
vector<int> Nout[100001];
int bfs(int n){
memset(d, -1, sizeof(d));
queue<int> q;
q.push(n);
d[n] = 0;
int c = n;
while (!q.empty()){
int x = q.front();
q.pop();
c = x;
for (auto& i : Nout[x]){
if (d[i] < 0){
q.push(i);
d[i] = d[x] + 1;
}
}
}
return c;
}
int main(){
ifstream f("darb.in");
ofstream of("darb.out");
int N, a, b;
f >> N;
for(int i=0;i<N;++i){
f >> a >> b;
Nout[a].push_back(b);
Nout[b].push_back(a);
}
int i = bfs(1);
of << d[bfs(i)]+1;
return 0;
}