#include "bits/stdc++.h" #define MAXN 300009 #define INF 1000000007 #define mp(x,y) make_pair(x,y) #define all(v) v.begin(),v.end() #define pb(x) push_back(x) #define wr cout<<"----------------"<1 and arr[i-1][j]=='1'){ adj[(i-2)*m+j].pb((i-1)*m+j); adj[(i-1)*m+j].pb((i-2)*m+j); } if(j>1 and arr[i][j-1]=='1'){ adj[(i-1)*m+j-1].pb((i-1)*m+j); adj[(i-1)*m+j].pb((i-1)*m+j-1); } } for(int i=1;i<=n*m;i++) if(!tin[i]) dfs(i,-1); printf("%d\n",n*m-ans); return 0; }