#include<iostream>
#include<set>
#include<vector>
using namespace std;
int main(){
int n, m, cnt, k, a[210][210] = {0};
cin >> n >> m;
for(int i = 0; i < m; i++){
int t1, t2;
cin >> t1 >> t2;
a[t1][t2] = 1;
a[t2][t1] = 1;
}
cin >> cnt;
while(cnt--){
cin >> k;
vector<int> v(k);
set<int> s;
int flag1 = 1, flag2 = 1;
for(int i = 0; i < k; i++){
scanf("%d", &v[i]);
s.insert(v[i]);
}
if(s.size() != n || k - 1 != n || v[0] != v[k-1]) flag1 = 0;
for(int i = 0; i < k-1; i++){
if(a[v[i]][v[i+1]] == 0) flag2 = 0;
}
printf("%s\n", flag1 && flag2 ? "YES" : "NO");
}
return 0;
}
原文:https://www.cnblogs.com/tsruixi/p/13051585.html