Pagini recente » Cod sursa (job #1113888) | Cod sursa (job #2943611) | Cod sursa (job #653133) | Cod sursa (job #837182) | Cod sursa (job #2664161)
#include <cstdio>
#include <cassert>
#include <vector>
using namespace std;
const int nmax = 100001;
vector< int > v[nmax];
int nivelMax, nodMax;
void dfs( int nod, int tata, int nivel ) {
if ( nivel > nivelMax ) {
nivelMax = nivel;
nodMax = nod;
}
for ( auto it = v[ nod ].begin(); it != v[ nod ].end(); it++ )
if ( *it != tata )
dfs( *it, nod, nivel + 1 );
}
int main() {
int n;
FILE *fin = fopen( "darb.in", "r" );
assert( fscanf( fin, "%d", &n ) == 1 );
for ( int i = 0; i < n - 1; i++ ) {
int a, b;
assert( fscanf( fin, "%d%d", &a, &b ) == 2 );
v[ a ].push_back( b );
v[ b ].push_back( a );
}
fclose( fin );
dfs( 1, 0, 1 );
dfs( nodMax, 0, 1 );
FILE *fout = fopen( "darb.out", "w" );
fprintf( fout, "%d\n", nivelMax );
fclose( fout );
return 0;
}