团体程序设计天梯赛 L2-025 分而治之 (25分)
题目链接:
L2-025 分而治之 (25分)
思路:
对每种方案,检查每个未被攻占的城市的相邻城市是否全被攻占即可
代码:
#include<bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1; char c = getchar();
while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
const int maxn = 1e4 + 5;
vector<int> G[maxn];
bool lost[maxn];
inline bool ok(int & n) {
for(int i = 1; i <= n; i++) if(!lost[i]) {
for(int & x : G[i]) if(!lost[x]) return false;
}
return true;
}
int main() {
#ifdef MyTest
freopen("Sakura.txt", "r", stdin);
#endif
int n = read(), m = read();
for(int i = 0; i < m; i++) {
int x = read(), y = read();
G[x].push_back(y);
G[y].push_back(x);
}
for(int k = read(); k--;) {
fill(lost, lost + n + 1, 0);
for(int np = read(); np--;) {
int x = read();
lost[x] = true;
}
puts(ok(n) ? "YES" : "NO");
}
return 0;
}