血的教训!! 格式输出一定要直接复制样例!!
红色警报后面竟然是’!’ 不是 ‘.’ 查了好久好久都没看出来 一度怀疑人生
题目很好理解 思路就是 每次攻占一个城市 就把城市相连的标记去掉 然后计算连通分量 如果连通分量增加2及以上,则说明是红色警报
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int m, n;
int mp[501][501] = {0};
int vis[501] = {0};
void dfs(int a)
{
for (int j = 0; j < n; j++)
{
if (mp[a][j] && vis[j] == 0)
{
vis[j] = 1;
dfs(j);
}
}
}
int fenliang()
{
memset(vis, 0, sizeof(vis));
int sum = 0;
for (int i = 0; i < n; i++)
{
if (vis[i] == 0)
{
vis[i] = 1;
sum++;
dfs(i);
}
}
return sum;
}
int main()
{
cin >> n >> m;
while (m--)
{
int i, j;
cin >> i >> j;
mp[i][j] = 1;
mp[j][i] = 1;
}
int k;
cin >> k;
int fn = fenliang();
for (int i = 0; i < k; i++)
{
int city;
cin >> city;
for (int f = 0; f < n; f++)
{
mp[city][f] = 0;
mp[f][city] = 0;
}
int fc = fenliang();
if (fc - fn > 1)
cout << "Red Alert: City " << city << " is lost!\n";
else
cout << "City " << city << " is lost.\n";
fn = fc;
}
if (k == n)
cout << "Game Over.\n";
return 0;
}