#include #include using namespace std; int H,W; int A[3001][3001]; int res = 0; const int dy[] = {1, 0, -1, 0}, dx[] = {0, 1, 0, -1}; void dfs(int x, int y){ A[y][x] = 0; if(y+1=0 && A[y-1][x]) dfs(x,y-1); if(x+1=0 && A[y][x-1]) dfs(x-1,y); } int main(){ cin >> H >> W; for(int j=0; j> A[j][i]; for(int j=0;j> que; que.push(make_pair(j, i)); A[j][i]=0; res++; while(!que.empty()){ int y= que.front().first; int x = que.front().second; que.pop(); for(int k=0; k<4; k++){ int ny = y+dy[k]; int nx = x+dx[k]; if (!(0 <= ny && ny < H && 0 <= nx && nx < W)) continue; if (A[ny][nx] == 1) { A[ny][nx] = 0; que.push(make_pair(ny, nx)); } } } } } cout << res << endl; }