#include using namespace std; const int kMAX_H = 60; const int kMAX_W = 60; string S[kMAX_H]; int color[kMAX_H][kMAX_W]; bool used[kMAX_H][kMAX_H]; int H, W, red, blue; int dr[] = {1, 0, -1, 0}, dc[] = {0, 1, 0, -1}; bool DFS(int row, int col, int c) { used[row][col] = true; color[row][col] = c; if (c == 1) red++; else blue--; for (int i = 0; i < 4; i++) { int nr = row + dr[i], nc = col + dc[i]; if (0 <= nr && nr < H && 0 <= nc && nc < W && !used[nr][nc] && !DFS(nr, nc, -c)) { return false; } } return true; } void Solve() { for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (S[i][j] == '.') used[i][j] = true; } } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (!used[i][j] && !DFS(i, j, 1)) { cout << "NO" << endl; return; } } } if ((red + blue) % 2 == 0) { cout << "YES" << endl; } else { cout << "NO" << endl; } } int main() { cin >> H >> W; for (int i = 0; i < H; i++) { cin >> S[i]; } Solve(); return 0; }