#include #include using namespace std; int H,W; int ans=0; bool not1(vector> A) { int i,j; for (i=1;i<=H;i++){ for (j=1;j<=W;j++){ if (A[i][j]==1){ return false; } } } return true; } void check(vector> &A,int I,int J,int &index) { if (A[I][J]==1){ ans++; index++; A[I][J]=index; if (A[I-1][J]==1){ A[I-1][J]=index; } if (A[I+1][J]==1){ A[I+1][J]=index; } if (A[I][J-1]==1){ A[I][J-1]=index; } if (A[I][J+1]==1){ A[I][J+1]=index; } int i,j; for (i=I;i<=H;i++){ for (j=J+1;j<=W;j++){ if (A[i][j]==0 ){ continue; } if (A[i-1][j]==index || A[i+1][j]==index || A[i][j-1]==index || A[i][j+1]==index){ A[i][j]=index; if (A[i-1][j]==1){ A[i-1][j]=index; } if (A[i+1][j]==1){ A[i+1][j]=index; } if (A[i][j-1]==1){ A[i][j-1]=index; } if (A[i][j+1]==1){ A[i][j+1]=index; } } } } } } int main(int argc, char* argv[]) { cin>>H>>W; int n0=0,n1=0; vector> A(H+2,vector(W+2)); int i,j; for (i=1;i<=H;i++){ for (j=1;j<=W;j++){ cin>>A[i][j]; if (A[i][j]==0){ n0++; }else{ n1++; } } } if (n0==H*W){ cout<<0<