#include #include using namespace std; const int dy[] = {1, 0, -1, 0}, dx[] = {0, 1, 0, -1}; int main(){ int H,W, res=0; int A[3001][3001]; 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, x = que.front().second; que.pop(); for(int k=0; k<4; k++){ int ny = y+dy[k], nx = x+dx[k]; if (!(0 <= ny && ny < H && 0 <= nx && nx < W)) continue; if (A[ny][nx]) { A[ny][nx] = 0; que.push(make_pair(ny, nx)); } } } } } cout << res << endl; }