#include #include const int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1}; int H, W, Q, R, C, X; int A[200][200]; bool _array[200][200]; void dfs(int r, int c, int prevColor, int color){ _array[r][c] = 1; A[r][c] = color; for(int i=0;i<4;i++){ int nr = r + dx[i], nc = c + dy[i]; if(!_array[nr][nc] && 0 <= nr && nr < H && 0 <= nc && nc < W && A[nr][nc] == prevColor){ dfs(nr, nc, prevColor, color); } } } int main(){ scanf("%d %d", &H, &W); for(int i=0;i