#include <iostream>
using namespace std;
const int N = 510, M = 5010;
int n, m;
int f[N];
struct edge{
int a, b;
}e[M];
int find(int x)
{
if(f[x] != x) f[x] = find(f[x]);
return f[x];
}
int main()
{
cin >> n >> m;
for(int i = 0; i < n; i++) f[i] = i;
for(int i = 0; i < m; i++) cin >> e[i].a >> e[i].b;
int k;
cin >> k;
int cnt = n;
for(int i = 0; i < m; i++)
{
int fa = find(e[i].a), fb = find(e[i].b);
if(fa != fb)
{
f[fb] = fa;
cnt--;
}
}
for(int j = 0; j < k; j ++)
{
int city;
cin >> city;
for(int i = 0; i < n; i++) f[i] = i;
for(int i = 0; i < m; i++)
if(e[i].a == city || e[i].b == city)
e[i].a = e[i].b = city;
int temp = n - j - 1;
for(int i = 0;i < m; i++)
{
int fa = find(e[i].a), fb = find(e[i].b);
if(fa != fb)
{
f[fb] = fa;
temp--;
}
}
if(temp <= cnt) cout << "City " << city << " is lost." << endl;
else cout << "Red Alert: City " << city << " is lost!" << endl;
cnt = temp;
}
cout << "Game Over." << endl;
}
有一个测试点没有通过,没有找到问题,占个坑记录一下