#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define LLMAX LLONG_MAX #define IMAX INT_MAX int main() { int n, m; cin >> n >> m; int safeN = 0; char field[m][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> field[j][i]; safeN += (field[j][i] == '.'); } } if (safeN == 2 && n*m == 2) { cout << "YES" << endl; return 0; } if (n == 1 || m == 1) { cout << "NO" << endl; return 0; } bool vis[m][n]; memset(vis, false, sizeof(vis)); bool ok = false; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (field[j][i] == '.') { int dx[] = {1,0,-1,0}; int dy[] = {0,-1,0,1}; for (int p = 0; p < 4; p++) { int nx = j+dx[p]; int ny = i+dy[p]; int cnt = 1; if (!(nx >= 0 && ny >= 0 && nx < m && ny < n && field[nx][ny] == '.')) continue; memset(vis, false, sizeof(vis)); nx = j; ny = i; vis[j][i] = true; for (int k = 0; k < 4; k++) { nx += dx[(k+p)%4]; ny += dy[(k+p)%4]; while (nx >= 0 && ny >= 0 && nx < m && ny < n && field[nx][ny] == '.' && !vis[nx][ny]) { cnt++; vis[nx][ny] = true; // std::cout << nx << " " << ny << std::endl; nx += dx[(k+p)%4]; ny += dy[(k+p)%4]; if (!(nx >= 0 && ny >= 0 && nx < m && ny < n && field[nx][ny] == '.' && !vis[nx][ny])) { nx -= dx[(k+p)%4]; ny -= dy[(k+p)%4]; if (cnt == safeN) { for (int e = 0; e < 4; e++) { nx += dx[e]; ny += dy[e]; if (nx == i && ny == j) { cout << "YES" << endl; return 0; } nx -= dx[e]; ny -= dy[e]; } } break; } } } // cout << endl; } ok = true; } if (ok) break; } if (ok) break; } ok = false; int cnt2 = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (field[j][i] == '.') { int dx[] = {1,0,-1,0}; int dy[] = {0,-1,0,1}; for (int p = 0; p < 4; p++) { int nx1 = j+dx[p]; int ny1 = i+dy[p]; int nx2 = j+dx[(p+1)%4]; int ny2 = i+dy[(p+1)%4]; int nx3 = j+dx[p]+dx[(p+1)%4]; int ny3 = i+dy[p]+dy[(p+1)%4]; if (!(nx1 >= 0 && ny1 >= 0 && nx1 < m && ny1 < n && field[nx1][ny1] == '.')) continue; if (!(nx2 >= 0 && ny2 >= 0 && nx2 < m && ny2 < n && field[nx2][ny2] == '.')) continue; if (!(nx3 >= 0 && ny3 >= 0 && nx3 < m && ny3 < n && field[nx3][ny3] == '#')) continue; memset(vis, false, sizeof(vis)); cnt2++; int cnt = 1; vis[j][i] = true; int nx = j, ny = i; p++; for (int k = 0; k < 6; k++) { nx += dx[(k+p)%4]; ny += dy[(k+p)%4]; while (nx >= 0 && ny >= 0 && nx < m && ny < n && field[nx][ny] == '.' && !vis[nx][ny]) { cnt++; vis[nx][ny] = true; // if (j == 43 && i == 18) { // std::cout << nx << " " << ny << std::endl; // } nx += dx[(k+p)%4]; ny += dy[(k+p)%4]; if (!(nx >= 0 && ny >= 0 && nx < m && ny < n && field[nx][ny] == '.' && !vis[nx][ny])) { nx -= dx[(k+p)%4]; ny -= dy[(k+p)%4]; if (cnt == safeN) { for (int e = 0; e < 4; e++) { nx += dx[e]; ny += dy[e]; if (nx == j && ny == i) { cout << "YES" << endl; return 0; } nx -= dx[e]; ny -= dy[e]; } } } } // cout << endl; } break; } } if (cnt2 >= 6) break; } if (cnt2 >= 6) break; } cout << "NO" << endl; }