#include #include #include using namespace std;

vector<vector> graph; vector visited;

void bfs(int start) { queue q; q.push(start); visited[start] = true; while (!q.empty()) { int cur = q.front(); q.pop(); for (int i = 0; i < graph[cur].size(); i++) { int next = graph[cur][i]; if (!visited[next]) { visited[next] = true; q.push(next); } } } }

int main() { int N, M; cin >> N >> M; graph.resize(N); visited.resize(N, false); for (int i = 0; i < M; i++) { int city1, city2; cin >> city1 >> city2; graph[city1].push_back(city2); graph[city2].push_back(city1); } int K; cin >> K; vector lostCities(K); for (int i = 0; i < K; i++) { cin >> lostCities[i]; }

for (int i = 0; i < K; i++) {
    int lostCity = lostCities[i];
    visited.assign(N, false);
    bfs(lostCity);
    bool isConnected = true;
    for (int j = 0; j < N; j++) {
        if (!visited[j]) {
            isConnected = false;
            break;
        }
    }
    if (isConnected) {
        cout << 'City ' << lostCity << ' is lost.' << endl;
    } else {
        cout << 'Red Alert: City ' << lostCity << ' is lost!' << endl;
    }
}
if (K == N) {
    cout << 'Game Over.' << endl;
}

return 0;

}


原文地址: https://www.cveoy.top/t/topic/o5BM 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录