Pagini recente » Cod sursa (job #1094842) | Cod sursa (job #1324439) | Cod sursa (job #2127260) | Cod sursa (job #662514) | Cod sursa (job #2793467)
#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];
struct elem {int n, d;};
queue<elem> q;
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, 0});
for(;!q.empty();q.pop())
for(auto i : g[q.front().n])
if(!f[i])
f[i] = 1,
q.push({i, 0}),
s = i;
memset(f+1, 0, n*sizeof(int));
q.push({s, 1});
for(;!q.empty();q.pop())
for(auto i : g[q.front().n])
if(!f[i])
f[i] = 1,
q.push({i, q.front().d + 1}),
l = q.front().d + 1;
out << l;
return 0;
}