Adjacency list of graph
map < int , vector < pair < int , int > > > adj ; for ( int i = 0 ; i < v ; i ++ ) { for ( int j = i + 1 ; j < v ; j ++ ) { if ( graph [ i ] [ j ] != 0 ) { adj [ i ] . push_back ( { graph [ i ] [ j ] , j } ) ; adj [ j ] . push_back ( { graph [ i ] [ j ] , i } ) ; } } }