5 4
0 1
1 3
3 0
0 4
5
1 2 0 4 3

### 输出样例：

City 1 is lost.
City 2 is lost.
Red Alert: City 0 is lost!
City 4 is lost.
City 3 is lost.
Game Over.

### AC代码：

``````#include <bits/stdc++.h>
using namespace std;
#define MAX 501
int N;
bool lost[MAX];
bool Edge[MAX][MAX];
void dfs(int x)   //图的深度优先遍历
{
lost[x] = true;
for (int i = 0; i < N; i++)
{
if(!lost[i] && Edge[x][i])
{
dfs(i);
}
}
}
int getCount()  //计算图的连通分量
{
int count = 0;
memset(lost,false,sizeof(lost));
for (int i = 0; i < N; i++)
{
if(!lost[i])
{
dfs(i);
count++;
}
}
return count;
}
int main()
{
memset(Edge,false,sizeof(Edge));
int M;
cin >> N >> M;
for (int i = 0; i < M; i++)
{
int x,y;
cin >> x >> y;
Edge[x][y] = Edge[y][x] = 1;
}
int count = getCount();
int K;
cin >> K;
for (int i = 0; i < K; i++)
{
int city;
cin >> city;
for (int j = 0; j < N; j++)
{
if(Edge[city][j] == 1)
{
Edge[city][j] = 0;
Edge[j][city] = 0;
}
}
int temp = getCount();
//被攻占的城市会变成一个单独的城市，连通分量会加一
if(temp <= count+1)  //若当前图的连通分量没有改变
{
printf("City %d is lost.\n", city);
}
else  //若图的连通性发生了改变
{
printf("Red Alert: City %d is lost!\n", city);
}
count = temp;  //更新图的连通性
if(i == N - 1)
{
printf("Game Over.\n");
}
}
return 0;
}``````