A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at least one vertex of the set.
顶点的集合,使得图中每条边都至少有一个顶点在其中
那么每次给出点的集合,用hash标记下判断是否覆盖所有边即可~
⽤vector v[n]保存某结点属于的某条边的编号,在前面给边的两点时,把对应的边加入。
// incident to
#include<bits/stdc++.h>
using namespace std;
const int maxn=10010;
vector<int> v[maxn];
int h[maxn];
int main(){
int n,m;
scanf("%d %d",&n,&m);
for(int i=0;i<m;i++){
int x,y;
scanf("%d %d",&x,&y);
v[x].push_back(i);v[y].push_back(i);
}
int k;
scanf("%d",&k);
while(k--){
fill(h,h+m,0);
int num;
scanf("%d",&num);
for(int i=0;i<num;i++){
int x;
scanf("%d",&x);
for(int j=0;j<v[x].size();j++) h[v[x][j]]++;
}
bool flag=true;
for(int i=0;i<m;i++){
if(h[i]==0){
flag=false;
printf("No\n");break;
}
}
if(flag) printf("Yes\n");
}
return 0;
}