If a policeman is at any point of connection , leave that connection . Insert the connect otherwise .
if ( A [ paths [ i ] [ 0 ] ] != 1 && A [ paths [ i ] [ 1 ] ] != 1 ) { ArrayList < Integer > list = adj . getOrDefault ( paths [ i ] [ 0 ] , new ArrayList < > ( ) ) ; list . add ( paths [ i ] [ 1 ] ) ; adj . put ( paths [ i ] [ 0 ] , list ) ; } } }