Try to find edges i -> j and j -> k which having weight 1
for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { if ( j == i ) { continue ; } if ( adj [ i ] [ j ] == '1' ) { if ( mp1 [ j ] . size ( ) ) { int k = mp1 [ j ] [ 0 ] ;