filling edge data structure
vector < int > edge [ N ] ; for ( int i = 0 ; i < N - 1 ; i ++ ) { edge [ edges [ i ] [ 0 ] ] . push_back ( edges [ i ] [ 1 ] ) ; edge [ edges [ i ] [ 1 ] ] . push_back ( edges [ i ] [ 0 ] ) ; } int res = INT_MAX ;