https://pintia.cn/problem-sets/994805342720868352/problems/994805346428633088
图题。题目提出一个概念让你去推。明白概念即可。
#include <iostream>
#include <vector>
#include <unordered_set>
using namespace std;
const int SIZE = 10005;
vector<int> adj[SIZE];
int main() {
int N, M, v1, v2;
cin >> N >> M;
for (int i = 0; i < M; i ++) {
cin >> v1 >> v2;
adj[v1].push_back(v2);
adj[v2].push_back(v1);
}
int K, Nv, tv;
cin >> K;
unordered_set<int> st;
for (int i = 0; i < K; i ++) {
cin >> Nv;
st.clear();
for (int j = 0; j < Nv; j ++) {
cin >> tv;
st.insert(tv);
}
bool flag = true;
for (int v = 0; v < N; v ++) {
if (st.count(v) == 0) {
for (int u = 0; u < adj[v].size(); u ++) {
if (st.count(adj[v][u]) == 0) {
flag = false;
break;
}
}
}
if (!flag) break;
}
if (flag) cout << "Yes" << endl;
else cout << "No" << endl;
}
cin >> N;
return 0;
}