To store edges with weight '1'
vector < int > mp2 [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { if ( i == j ) { continue ; } if ( adj [ i ] [ j ] == '0' ) { mp1 [ i ] . push_back ( j ) ; } else { mp2 [ i ] . push_back ( j ) ; } } }