#54589: C++ (躲五星通緝其實可以躲在電車地下軌道裡)


MillionJudge (Millionaire is Online)


#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, M;
    cin >> N >> M;

    vector<string> g(N);
    int sx=-1, sy=-1, tx=-1, ty=-1;

    for (int i = 0; i < N; i++) {
        cin >> g[i];
        for (int j = 0; j < M; j++) {
            if (g[i][j] == 'S') { sx=i; sy=j; }
            if (g[i][j] == 'T') { tx=i; ty=j; }
        }
    }

    vector<vector<char>> vis(N, vector<char>(M, 0));
    queue<pair<int,int>> q;

    q.push({sx, sy});
    vis[sx][sy] = 1;

    int dr[4] = {1,-1,0,0};
    int dc[4] = {0,0,1,-1};

    while (!q.empty()) {
        auto [r, c] = q.front(); q.pop();

        for (int k = 0; k < 4; k++) {
            int nr = r + dr[k], nc = c + dc[k];
            if (nr < 0 || nr >= N || nc < 0 || nc >= M) continue;
            if (vis[nr][nc]) continue;
            if (g[nr][nc] == '#') continue; // 只有 # 不能走

            vis[nr][nc] = 1;
            q.push({nr, nc});
        }
    }

    if (vis[tx][ty]) cout << "mission passed respect+\n";
    else cout << "wasted\n";

    return 0;
}