If the matrix consists of only 0 ' s ▁ ▁ or ▁ only ▁ 1' s
if ( one . empty ( ) || M * N == one . size ( ) ) return -1 ; for ( int i = 0 ; i < M ; ++ i ) { for ( int j = 0 ; j < N ; ++ j ) { if ( grid [ i ] [ j ] == 1 ) continue ;