记录一个菜逼的成长。。
还记得这是去年决赛时L2的第一道题,当时还是有点懵。现在看看就是暴力的dfs。。
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cctype>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define cl(a,b) memset(a,b,sizeof(a))
#define clr clear()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int maxn = 500 + 10;
int vis[maxn],g[maxn][maxn],flag[maxn];
int n,m,k,area;
void dfs(int x)
{
vis[x] = 1;
for( int i = 0; i < n; i++ ){
if(!vis[i] && !flag[i] && g[x][i]){
dfs(i);
}
}
}
int main()
{
cin>>n>>m;
for( int i = 0; i < m; i++ ){
int u,v;
cin>>u>>v;
g[u][v] = 1;
g[v][u] = 1;
}
area = 0;
for( int i = 0; i < n; i++ )
if(!vis[i])area++,dfs(i);
int last = area;
cin>>k;
while(k--){
int x;
cin>>x;
flag[x] = 1;
cl(vis,0),area = 0;
for( int i = 0; i < n; i++ )
if(g[x][i])g[x][i] = g[i][x] = 0;
//已经被摧毁的城市也是不算在内的
for( int i = 0; i < n; i++ )
if(!vis[i] && !flag[i])area++,dfs(i);
if(area > last){
printf("Red Alert: City %d is lost!\n",x);
}
else printf("City %d is lost.\n",x);
last = area;
}
for( int i = 0; i < n; i++ )
if(!flag[i])return 0;
puts("Game Over.");
return 0;
}