Pagini recente » Cod sursa (job #2554536) | Cod sursa (job #1861954) | Istoria paginii runda/dinamica01/clasament | Cod sursa (job #2059185) | Cod sursa (job #1480328)
#include <fstream>
#include <vector>
#include <bitset>
using namespace std;
ifstream is("darb.in");
ofstream os("darb.out");
#define MaxN 100001
int n, nod_max, dmax;
vector<int> G[MaxN], dist(MaxN);
bitset<MaxN> viz;
void Read();
void Dfs(int);
int main()
{
Read();
Dfs(1);
Dfs(nod_max);
os << dmax + 1;
is.close();
os.close();
return 0;
}
void Dfs(int i)
{
viz[i] = true;
for (const auto& p : G[i])
if (!viz[p])
{
dist[p] = dist[i] + 1;
if (dist[p] > dmax)
dmax = dist[p];
if (p > nod_max)
nod_max = p;
Dfs(p);
}
viz[i] = false;
dist[i] = 0;
}
void Read()
{
is >> n;
for (int i = 1, x, y; i < n; ++i)
{
is >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
}