按题目要求模拟就行,但是需要开vector,如果用二维数组会超时
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int>e[10010];
bool book[10010];
bool dfs(int u)
{
for(int i=0; i<e[u].size(); i++)
if(book[e[u][i]]==0)
return false;
return true;
}
int main()
{
int m,t,x,y;
cin>>n>>m;
while(m--)
{
cin>>x>>y;
e[x].push_back(y);
e[y].push_back(x);
}
cin>>t;
while(t--)
{
int i;
memset(book,0,sizeof(book));
int k;
cin>>k;
while(k--)
{
int z;
cin>>z;
book[z]=1;
}
for(i=1; i<=n; i++)
if(book[i]==0&&!dfs(i))
{
printf("NO\n");
break;
}
if(i==n+1)
printf("YES\n");
}
return 0;
}