#include<iostream>
#include<vector>
using namespace std;
vector<vector<int>> vm;
vector<bool> visit;
int main()
{
int M,N,L,X,a,b,c,a_bef;
cin >> M>>N;
vm.resize(M);
visit.resize(M);
for (int i = 0; i < N; i++)
{
cin >> a >> b;
a--;
b--;
vm[a].push_back(b);
vm[b].push_back(a);
}
cin >> L;
for (int i = 0; i < L; i++)
{
fill(visit.begin(), visit.end(), false);
cin >> X;
if (X!=M+1)
{
while (cin.get()!='\n')
{
cin >> c;
}
cout << "NO" << endl;
continue;
}
cin >> a;
a--;
a_bef = a;
visit[a] = true;
bool flag = false;
for (int j = 1; j < X-1; j++)
{
cin >> b;
b--;
//没有找到连接线或者访问一个已经访问过的节点
if((find(vm[a].begin(), vm[a].end(), b)==vm[a].end())||(visit[b]==true))
{
while (cin.get()!='\n')//清除后面的数据
{
cin >> c;
}
flag = true;
break;
}
visit[b] = true;
a = b;
}
if(flag==false)
{
cin >> c;
c--;
if (c == a_bef) {
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
}
else
{
cout << "NO" << endl;
}
}
system("pause");
return 0;
}
网友评论