#include using namespace std; using ll = long long; using pii = pair; using arr = array; int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1}; void Tsukikage() { int n, m; cin >> n >> m; vector g(n + 1, vector(m + 1)); int cnt = 0; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { cin >> g[i][j]; cnt += g[i][j] == '.'; } int res = 0, sx, sy; bool ok = 0; auto dfs = [&](auto dfs, int x, int y, int d) -> void { for (int i = 0; i < 2; i++) { int xx = x + dx[(d + i) % 4], yy = y + dy[(d + i) % 4]; if (xx < 1 or xx > n or yy < 1 or yy > m) continue; if (g[xx][yy] != '.') continue; res++; g[xx][yy] = '@'; if (xx == sx and yy == sy) { ok = 1; return; } dfs(dfs, xx, yy, (d + i) % 4); break; } }; auto undo = [&](auto undo, int x, int y) -> void { if (g[x][y] != '@') return; g[x][y] = '.'; for (int i = 0; i < 4; i++) { int xx = x + dx[i], yy = y + dy[i]; if (xx < 1 or xx > n or yy < 1 or yy > m) continue; if (g[xx][yy] != '@') continue; undo(undo, xx, yy); } }; auto Write = [&]() { // debug for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) cout << g[i][j]; cout << "\n"; } }; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { if (g[i][j] == '#') continue; // Write(); for (int d = 0; d < 4; d++) { res = 0, sx = i, sy = j; ok = 0; dfs(dfs, i, j, d); if (res == cnt and ok) { cout << "YES\n"; return; } g[i][j] = '@'; // 填充逻辑是最后一个填充起点,假如填充失败则起点是'.'而非'@',导致undo也会失败,所以直接给起点覆盖'@' undo(undo, i, j); } } cout << "NO\n"; } signed main() { ios::sync_with_stdio(false); cin.tie(0); // int _; // for (cin >> _; _; _--) Tsukikage(); return 0; }