模拟
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
// Scanner scan = new Scanner(System.in);
// int n = scan.nextInt();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
ArrayList<Integer>[] node = new ArrayList[n + 1];
Arrays.setAll(node, i -> new ArrayList<>());
int m = Integer.parseInt(st.nextToken());
for (int i = 0; i < m; i++) {
st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
node[a].add(b);
node[b].add(a);
}
st = new StringTokenizer(br.readLine());
int k = Integer.parseInt(st.nextToken());
for (int i = 0; i < k; i++) {
st = new StringTokenizer(br.readLine());
int t = Integer.parseInt(st.nextToken());
boolean[] isVisited = new boolean[n + 1];
for (int j = 0; j < t; j++) {
int q = Integer.parseInt(st.nextToken());
isVisited[q] = true;
}
boolean flag = true;
for (int j = 1; j <= n; j++) {
if (!isVisited[j]) {
if (node[j].isEmpty()) {
flag = false;
System.out.println("no");
break;
} else {
boolean flag1 = false;
for (int e : node[j]) {
if (isVisited[e]) {
flag1 = true;
break;
}
}
if (!flag1) {
System.out.println("no");
flag = false;
break;
}
}
}
}
if (flag) {
System.out.println("yes");
}
}
}
}