题目链接
https://pintia.cn/problem-sets/994805046380707840/problems/994805063963230208
思路对于每一个城市我们都有一个over
标记 over[i]=true
表示的是第
i
i
i 个城市已经被攻占下了,对于每一个城市被攻占后我们就将其标为true
并且将其所有联通的城市全都标记为true
(其实就是一个图的遍历),然后每次我们拿攻占前和攻占后的连通块的数量进行对比,如果发现连通块的数量增大了(除去被攻占的这个城市),那么说明国家被分割了,于是我们输出Red Alert: City k is lost!
否则我们只需要输出 ity k is lost.
,最后如果攻占的城市的数量为
n
n
n 的话,最后输出 Game Over.
#include
using namespace std;
#define ll long long
#define mod 1000000007
#define endl "\n"
#define PII pair
#define INF 0x3f3f3f3f
const int N = 5e2+10;
bool mp[N][N];
bool vis[N],over[N];
int n,m;
void dfs(int u){
if(vis[u]) return;
vis[u] = true;
for(int i = 0;i n>>m;
int u,v;
for(int i = 1;i >u>>v;
mp[u][v] = mp[v][u] = true;
}
int k,t,num = get_num();
cin>>k;
for(int i = 1;i >t;
over[t] = true;
int loc = get_num();
if(loc > num) {
cout
关注
打赏