Traverse through matrix and find pairs p1 and p2
for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( arr [ i ] [ j ] == '1' ) if ( p1 . first == -1 ) p1 = { i , j } ; else p2 = { i , j } ; } } p3 = p1 ; p4 = p2 ;