如果一个城市未被炸毁,那如果他可达的其他城市也未被炸毁,说明方案不可行。
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector<vector<int>> vec;//邻接表
int main() {
int n, m;
cin >> n >> m;
vec.resize(n + 10);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
vec[a].push_back(b);
vec[b].push_back(a);
}
int t;
cin >> t;
for (int i = 0; i < t; i++) {
int zh;
cin >> zh;
map<int, int> mp;//被炸毁的城市
for (int j = 0; j < zh; j++) {
int pno;
cin >> pno;
mp[pno] = 1;//该城市到任何城市均不可达
}
//检查
int flag = 1;
for (int j = 1; flag && j <= n; j++) {//遍历城市
if (mp[j]) continue;
for (int k = 0; k < vec[j].size(); k++) {
if (mp[vec[j][k]] == 0) {
flag = 0;
break;
}
}
}
if (!flag) {
cout << "NO" << '\n';
}
else {
cout << "YES" << '\n';
}
}
return 0;
}
标签:zh,int,分而治之,cin,025,++,L2,vec,pno
From: https://www.cnblogs.com/chengyiyuki/p/18082179