Pagini recente » Cod sursa (job #1509597) | Cod sursa (job #1380423) | Cod sursa (job #234623) | Cod sursa (job #768467) | Cod sursa (job #2793474)
#include <fstream>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;
ifstream in("darb.in");
ofstream out("darb.out");
int n, s, l;
bool f[100001];
vector<int> g[100001];
queue<int> q;
struct elem {int n, d;};
queue<elem> p;
void read()
{
in >> n;
int x, y;
for(int i = 1; i < n; ++i)
in >> x >> y,
g[x].push_back(y),
g[y].push_back(x);
}
int main()
{
read();
q.push(1);
for(;!q.empty();q.pop())
for(auto i : g[q.front()])
if(!f[i])
f[i] = 1,
q.push(i),
s = i;
memset(f, 0, sizeof(f));
p.push({s, 1});
for(;!p.empty();p.pop())
for(auto i : g[p.front().n])
if(!f[i])
f[i] = 1,
p.push({i, p.front().d + 1}),
l = p.front().d + 1;
out << l;
return 0;
}