Pagini recente » Cod sursa (job #2293713) | Cod sursa (job #1840391) | Istoria paginii runda/oni_2012_11-12_ziua_1 | Cod sursa (job #2622716) | Cod sursa (job #3302433)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("darb.in");
ofstream fout ("darb.out");
const int nmax=1e5+5;
vector <int> g[nmax];
int n, d[nmax];
void dfs (int node, int dist)
{
d[node]=dist;
for (auto i:g[node])
{
if (!d[i])
dfs(i,dist+1);
}
}
signed main()
{
fin >> n;
for (int i=1; i<n; i++)
{
int x, y;
fin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
dfs(1,1);
int dist=0, nod;
for (int i=1; i<=n; i++)
{
if (d[i]>dist)
{
dist=d[i];
nod=i;
}
d[i]=0;
}
dfs(nod,1);
dist=0;
for (int i=1; i<=n; i++)
dist=max(dist,d[i]);
fout << dist;
return 0;
}