Pagini recente » Cod sursa (job #2304297) | Cod sursa (job #1258652) | Cod sursa (job #2004783) | Cod sursa (job #188319) | Cod sursa (job #1488840)
#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();
for (auto& i : Nout[x])
if (d[i] < 0){
q.push(i);
d[i] = d[x] + 1;
c = i;
}
}
return c;
}
int main(){
fstream f("darb.in");
ofstream of("darb.out");
int N, a, b;
f >> N;
while (f >> a >> b){
Nout[a].push_back(b);
Nout[b].push_back(a);
}
of << d[bfs(bfs(1))]+1;
return 0;
}