Construct the graph
for ( int i = 0 ; i < edges . size ( ) ; i ++ ) { adj [ edges . get ( i ) . first ] . add ( edges . get ( i ) . second ) ; adj [ edges . get ( i ) . second ] . add ( edges . get ( i ) . first ) ; }