#pragma GCC optimize("Ofast", "unroll-loops") #include using namespace std; int N, M; void readNM(void){ cin >> N >> M; } bool isBlack(int i, int j){ static map, int> memo; // 1: 白, 2: 黒 static int black_found = 2; if (i == 0 && j == 0) return true; if (i == N - 1 && j == N - 1) return true; int tmp = memo[{i, j}]; if (tmp > 0) return (tmp == 2); if (black_found == M) return false; cout << (i + 1) << " " << (j + 1) << endl; string res; cin >> res; assert(res != "-1"); memo[{i, j}] = res == "Black" ? 2 : 1; if (res == "Black") ++black_found; return res == "Black"; } bool bfs(void){ queue> q; vector> visited(N, vector(N, 0)); q.emplace(0, 0); while (!q.empty()){ auto [x, y] = q.front(); q.pop(); // 上 if (x > 0 && !visited[x - 1][y] && isBlack(x - 1, y)){ visited[x - 1][y] = 1; q.emplace(x - 1, y); } // 下 if (x < N - 1 && !visited[x + 1][y] && isBlack(x + 1, y)){ if (x == N - 2 && y == N - 1) return true; visited[x + 1][y] = 1; q.emplace(x + 1, y); } // 右 if (y < N - 1 && !visited[x][y + 1] && isBlack(x, y + 1)){ if (x == N - 1 && y == N - 2) return true; visited[x][y + 1] = 1; q.emplace(x, y + 1); } // 左 if (y > 0 && !visited[x][y - 1] && isBlack(x, y - 1)){ visited[x][y - 1] = 1; q.emplace(x, y - 1); } } return false; } int main(void){ readNM(); if (bfs()) cout << "Yes" << endl; else cout << "No" << endl; return 0; }