Pagini recente » iconcurs6 | Cod sursa (job #2701781) | Borderou de evaluare (job #366941) | Cod sursa (job #1139103) | Cod sursa (job #2304965)
#include <bits/stdc++.h>
using namespace std;
const int mxn = 100 * 1000 + 10;
vector< int > g[ mxn ];
bitset< mxn > viz;
int n;
int mxv, mxd;
void dfs(int nod, int d){
viz[ nod ] = 1;
if(d > mxd){
mxv = nod;
mxd = d;
}
for(auto it: g[ nod ])
if(viz[ it ] == 0)
dfs(it, d + 1);
}
int main()
{
ifstream cin("darb.in");
ofstream cout("darb.out");
cin>> n;
for(int i = 1, x, y; i < n; i++){
cin>> x >> y;
g[ x ].push_back( y );
g[ y ].push_back( x );
}
dfs( 1, 1 );
viz = bitset< mxn >();
dfs( mxv, 1 );
cout<< mxd;
return 0;
}