Pagini recente » Cod sursa (job #1099481) | Cod sursa (job #1533817) | Cod sursa (job #1808218) | Cod sursa (job #620825) | Cod sursa (job #2978930)
#include <fstream>
#include <vector>
#define pb push_back
using namespace std;
ifstream cin ("darb.in");
ofstream cout ("darb.out");
int n;
int dmax,nodmax;
vector<int> g[100005];
void dfs (int nod,int p,int lvl)
{
if (lvl>dmax)
{
dmax = lvl;
nodmax = nod;
}
for (auto vf:g[nod])
{
if (vf == p)
continue;
dfs(vf,nod,lvl+1);
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int i,j;
cin >> n;
for (i=1;i<=n;i++)
{
int x,y;
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
dfs(1,0,0);
dmax = 0;
dfs(nodmax,0,0);
cout << dmax + 1;
return 0;
}