You are given a rooted tree consisting of $n$ vertices numbered from $1$ to $n$. The root of the tree is a vertex number $1$.

A tree is a connected undirected graph with $n-1$ edges.

You are given $m$ queries. The $i$-th query consists of the set of $k_i$ distinct vertices $v_i[1], v_i[2], \dots, v_i[k_i]$. Your task is to say if there is a path from the root to some vertex $u$ such that each of the given $k$ vertices is either belongs to this path or has the distance $1$ to some vertex of this path.


-----Input-----

The first line of the input contains two integers $n$ and $m$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m \le 2 \cdot 10^5$) — the number of vertices in the tree and the number of queries.

Each of the next $n-1$ lines describes an edge of the tree. Edge $i$ is denoted by two integers $u_i$ and $v_i$, the labels of vertices it connects $(1 \le u_i, v_i \le n, u_i \ne v_i$).

It is guaranteed that the given edges form a tree.

The next $m$ lines describe queries. The $i$-th line describes the $i$-th query and starts with the integer $k_i$ ($1 \le k_i \le n$) — the number of vertices in the current query. Then $k_i$ integers follow: $v_i[1], v_i[2], \dots, v_i[k_i]$ ($1 \le v_i[j] \le n$), where $v_i[j]$ is the $j$-th vertex of the $i$-th query.

It is guaranteed that all vertices in a single query are distinct.

It is guaranteed that the sum of $k_i$ does not exceed $2 \cdot 10^5$ ($\sum\limits_{i=1}^{m} k_i \le 2 \cdot 10^5$).


-----Output-----

For each query, print the answer — "YES", if there is a path from the root to some vertex $u$ such that each of the given $k$ vertices is either belongs to this path or has the distance $1$ to some vertex of this path and "NO" otherwise.


-----Example-----
Input
10 6
1 2
1 3
1 4
2 5
2 6
3 7
7 8
7 9
9 10
4 3 8 9 10
3 2 4 6
3 2 1 5
3 4 8 2
2 6 10
3 5 4 7

Output
YES
YES
YES
YES
NO
NO



-----Note-----

The picture corresponding to the example:

[Image]

Consider the queries.

The first query is $[3, 8, 9, 10]$. The answer is "YES" as you can choose the path from the root $1$ to the vertex $u=10$. Then vertices $[3, 9, 10]$ belong to the path from $1$ to $10$ and the vertex $8$ has distance $1$ to the vertex $7$ which also belongs to this path.

The second query is $[2, 4, 6]$. The answer is "YES" as you can choose the path to the vertex $u=2$. Then the vertex $4$ has distance $1$ to the vertex $1$ which belongs to this path and the vertex $6$ has distance $1$ to the vertex $2$ which belongs to this path.

The third query is $[2, 1, 5]$. The answer is "YES" as you can choose the path to the vertex $u=5$ and all vertices of the query belong to this path.

The fourth query is $[4, 8, 2]$. The answer is "YES" as you can choose the path to the vertex $u=9$ so vertices $2$ and $4$ both have distance $1$ to the vertex $1$ which belongs to this path and the vertex $8$ has distance $1$ to the vertex $7$ which belongs to this path.

The fifth and the sixth queries both have answer "NO" because you cannot choose suitable vertex $u$.

Difficulty: HARD
Tags: Tree algorithms

Graph algorithms

Graph traversal

Starter code:

Solutions:
import sys
input = sys.stdin.readline
(n, m) = [int(i) for i in input().split()]
graph = [[] for i in range(n)]
for j in range(n - 1):
	(v, u) = [int(i) - 1 for i in input().split()]
	graph[v].append(u)
	graph[u].append(v)
parent = [0] * n
tin = [0] * n
tout = [0] * n
time = 0
queue = [(0, 0)]
while queue:
	(current, visit) = queue.pop()
	if visit == 0:
		queue.append((current, 1))
		time += 1
		tin[current] = time
		for child in graph[current]:
			if child != parent[current]:
				parent[child] = current
				queue.append((child, 0))
	else:
		tout[current] = time
for j in range(m):
	q = [int(i) - 1 for i in input().split()]
	q = q[1:]
	for i in range(len(q)):
		q[i] = parent[q[i]]
	cin = 1
	cout = n
	for i in q:
		cin = max(cin, tin[i])
		cout = min(cout, tout[i])
	if cin > cout:
		print('NO')
	else:
		print('YES')


from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

def main():
	(n, m) = readIntArr()
	adj = [[] for _ in range(n + 1)]
	for _ in range(n - 1):
		(u, v) = readIntArr()
		adj[u].append(v)
		adj[v].append(u)
	parent = [-1 for _ in range(n + 1)]
	start = [0 for _ in range(n + 1)]
	end = [0 for _ in range(n + 1)]
	depths = [0 for _ in range(n + 1)]
	time = [0]

	@bootstrap
	def dfs(node, p, d):
		depths[node] = d
		parent[node] = p
		start[node] = time[0]
		time[0] += 1
		for nex in adj[node]:
			if nex != p:
				yield dfs(nex, node, d + 1)
		end[node] = time[0]
		yield None
	dfs(1, -1, 0)
	ans = []
	for _ in range(m):
		q = readIntArr()[1:]
		nodeWithMaxDepth = q[0]
		for node in q:
			if depths[node] > depths[nodeWithMaxDepth]:
				nodeWithMaxDepth = node
		deepestNodeStart = start[nodeWithMaxDepth]
		deepestNodeEnd = end[nodeWithMaxDepth]
		ok = True
		for node in q:
			if node != 1:
				node = parent[node]
			nodeStart = start[node]
			nodeEnd = end[node]
			if nodeStart <= deepestNodeStart and nodeEnd >= deepestNodeEnd:
				pass
			else:
				ok = False
				break
		if ok:
			ans.append('YES')
		else:
			ans.append('NO')
	multiLineArrayPrint(ans)
	return
import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]
inf = float('inf')
MOD = 10 ** 9 + 7
main()


import sys, math
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.buffer.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
mod = 998244353
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
T = [0]

@bootstrap
def dfs(T, par, val, tin, tout, x, p=-1, cnt=0):
	tin[x] = T[0]
	val[x] = cnt
	T[0] += 1
	for i in g[x]:
		if i != p:
			yield dfs(T, par, val, tin, tout, i, x, cnt + 1)
	par[x] = p
	tout[x] = T[0]
	T[0] += 1
	yield
(n, m) = mdata()
g = [set() for i in range(n)]
for i in range(n - 1):
	(a, b) = mdata()
	g[a - 1].add(b - 1)
	g[b - 1].add(a - 1)
cnt = 1
tin = [0] * n
tout = [0] * n
s = []
par = [0] * n
val = [0] * n
dfs(T, par, val, tin, tout, 0)
for i in range(m):
	l = list(mdata())
	flag = True
	d = dd(set)
	max1 = 0
	ind = 0
	for j in l[1:]:
		if val[j - 1] > max1:
			max1 = val[j - 1]
			ind = j - 1
	for j in l[1:]:
		if j - 1 != ind and j != 1:
			if tin[par[j - 1]] < tin[ind] and tout[par[j - 1]] > tout[ind]:
				continue
			flag = False
			break
	if flag == True:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

def put():
	return map(int, input().split())

def dfs():
	t = 0
	s = [(1, 1)]
	while s:
		(i, state) = s.pop()
		if state:
			t += 1
			tin[i] = t
			s.append((i, 0))
			for j in tree[i]:
				if parent[j] == 0:
					parent[j] = i
					height[j] = height[i] + 1
					s.append((j, 1))
		else:
			t += 1
			tout[i] = t

def check(i, j):
	return tin[i] <= tin[j] and tout[j] <= tout[i]
(n, m) = put()
(height, tin, tout, parent) = ([0] * (n + 1), [0] * (n + 1), [0] * (n + 1), [0] * (n + 1))
tree = [[] for i in range(n + 1)]
for i in range(n - 1):
	(x, y) = put()
	tree[x].append(y)
	tree[y].append(x)
parent[1] = 1
dfs()
for i in range(m):
	l = list(put())
	k = l[0]
	for j in range(1, k + 1):
		l[j] = parent[l[j]]
	d = 1
	for j in range(1, k + 1):
		if height[d] < height[l[j]]:
			d = l[j]
	ans = True
	for j in range(1, k + 1):
		ans = ans and check(l[j], d)
	ans = 'YES' if ans else 'NO'
	print(ans)


import time
import os, sys
from io import BytesIO, IOBase
from types import GeneratorType
from bisect import bisect_left, bisect_right
from collections import defaultdict as dd, deque as dq, Counter as dc
import math, string, heapq as h
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def getInt():
	return int(input())

def getStrs():
	return input().split()

def getInts():
	return list(map(int, input().split()))

def getStr():
	return input()

def listStr():
	return list(input())

def getMat(n):
	return [getInts() for _ in range(n)]

def getBin():
	return list(map(int, list(input())))

def isInt(s):
	return '0' <= s[0] <= '9'

def ceil_(a, b):
	return a // b + (a % b > 0)

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
(N, M) = getInts()
G = [[] for _ in range(N)]
for _ in range(N - 1):
	(U, V) = getInts()
	U -= 1
	V -= 1
	G[U].append(V)
	G[V].append(U)
used = [0] * N
parent = [-1] * N
tin = [0] * N
tout = [0] * N
depth = [0] * N
global curr
curr = 1

@bootstrap
def dfs(node):
	global curr
	tin[node] = curr
	curr += 1
	for neigh in G[node]:
		if neigh != parent[node]:
			parent[neigh] = node
			depth[neigh] = depth[node] + 1
			yield dfs(neigh)
	tout[node] = curr
	curr += 1
	yield
dfs(0)

def path_(u, v):
	return tin[u] <= tin[v] and tout[v] <= tout[u] or (tin[v] <= tin[u] and tout[u] <= tout[v])
for m in range(M):
	(K, *V) = getInts()
	V = sorted(list(set([(depth[parent[v - 1]], parent[v - 1]) for v in V if v != 1])))
	for i in range(len(V) - 1):
		if not path_(V[i + 1][1], V[i][1]):
			print('NO')
			break
	else:
		print('YES')


import os
import sys
from io import BytesIO, IOBase

def dfs(graph, start=0):
	n = len(graph)
	visited = [False] * n
	(tin, tout, par) = ([0] * n, [0] * n, [0] * n)
	t = 0
	stack = [start]
	while stack:
		start = stack[-1]
		if not visited[start]:
			visited[start] = True
			t += 1
			tin[start] = t
			for child in graph[start]:
				if not visited[child]:
					par[child] = start
					stack.append(child)
		else:
			stack.pop()
			t += 1
			tout[start] = t
	return (tin, tout, par)

def main():
	(n, m) = map(int, input().split())
	e = [[] for _ in range(n + 1)]
	for _ in range(n - 1):
		(u, v) = map(int, input().split())
		e[u].append(v)
		e[v].append(u)
	e[0].append(1)
	e[1].append(0)
	(tin, tout, par) = dfs(e)
	for _ in range(m):
		a = list(map(int, input().split()))
		a = a[1:]
		a = [par[x] for x in a]
		lst = 0
		for x in a:
			if tin[x] >= tin[lst]:
				lst = x
		for x in a:
			if tin[x] <= tin[lst] and tout[lst] <= tout[x]:
				continue
			else:
				print('NO')
				break
		else:
			print('YES')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline
N = 2 * 10 ** 5 + 10
(st, en) = ([0] * N, [0] * N)
p = [-1] * N
g = [[] for _ in range(N)]
dist = [0] * N
stack = []

def isPar(u, v):
	return st[u] <= st[v] and en[v] <= en[u]

def dfs():
	vis = [False] * N
	stack.append((1, -1, 0))
	T = 0
	while stack:
		(u, pr, d) = stack[-1]
		if not vis[u]:
			vis[u] = True
			st[u] = T
			T += 1
			p[u] = pr
			dist[u] = d
			for v in g[u]:
				if v == pr:
					continue
				stack.append((v, u, d + 1))
		else:
			en[u] = T
			T += 1
			stack.pop()
(n, m) = map(int, input().split())
for _ in range(n - 1):
	(u, v) = map(int, input().split())
	g[u].append(v)
	g[v].append(u)
dfs()
for _ in range(m):
	li = list(map(int, input().split()))[1:]
	for i in range(len(li)):
		if p[li[i]] != -1:
			li[i] = p[li[i]]
		else:
			li[i] = 1
	down = li[0]
	for el in li:
		if dist[down] < dist[el]:
			down = el
	ok = True
	for el in li:
		ok = ok and isPar(el, down)
	print(['NO', 'YES'][ok])


from collections import defaultdict, Counter, deque
import threading
import sys
input = sys.stdin.readline

def ri():
	return int(input())

def rs():
	return input()

def rl():
	return list(map(int, input().split()))

def rls():
	return list(input().split())
threading.stack_size(10 ** 8)
sys.setrecursionlimit(10 ** 6)

def main():
	(n, m) = rl()
	g = defaultdict(list)
	for _ in range(n - 1):
		(u, v) = rl()
		g[u].append(v)
		g[v].append(u)
	global T
	T = 0
	tin = [-1] * (n + 1)
	tou = [-1] * (n + 1)
	dep = [-1] * (n + 1)
	par = [-1] * (n + 1)

	def dfs(cn, p, d):
		global T
		tin[cn] = T
		dep[cn] = d
		par[cn] = p
		T += 1
		for nn in g[cn]:
			if nn != p:
				dfs(nn, cn, d + 1)
		tou[cn] = T
		T += 1
	dfs(1, -1, 0)
	for q in range(m):
		a = rl()
		a = a[1:]
		og = a[0]
		for i in a:
			if dep[i] > dep[og]:
				og = i
		for i in range(len(a)):
			if a[i] == og:
				continue
			if par[a[i]] != -1:
				a[i] = par[a[i]]
		pos = True
		for i in a:
			pos &= tin[i] <= tin[og] and tou[i] >= tou[og]
		print(['NO', 'YES'][pos])
	pass
threading.Thread(target=main).start()


import sys
input = sys.stdin.readline
sys.setrecursionlimit(50000)
(n, m) = map(int, input().split())
E = [[] for _ in range(n + 1)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	E[a].append(b)
	E[b].append(a)
D = [0] * (n + 1)
P = [0] * (n + 1)
Tin = [0] * (n + 1)
Tout = [0] * (n + 1)
T = 0

def dfs(v, d, p):
	global T
	P[v] = p
	D[v] = d
	Tin[v] = T
	T += 1
	for n in E[v]:
		if n == p:
			continue
		dfs(n, d + 1, v)
	Tout[v] = T
	T += 1

def dfs2(v, d, p):
	global n
	Q = [(1, 0, 1)]
	V = [False] * (n + 1)
	T = 0
	while Q:
		(v, d, p) = Q[-1]
		if not V[v]:
			V[v] = True
			Tin[v] = T
			T += 1
			P[v] = p
			D[v] = d
			for n in E[v]:
				if n == p:
					continue
				Q.append((n, d + 1, v))
		else:
			Tout[v] = T
			T += 1
			Q.pop()
dfs2(1, 0, 1)
for _ in range(m):
	(nq, *Q) = map(int, input().split())
	v = Q[0]
	for q in Q:
		if D[q] > D[v]:
			v = q
	ok = True
	for q in Q:
		p = P[q]
		ok &= Tin[v] >= Tin[p] and Tout[v] <= Tout[p]
	print('YES' if ok else 'NO')


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify, nlargest
from copy import deepcopy
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))

def inpl_1():
	return list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))
(n, m) = inpl()
g = [[] for _ in range(n)]
ab = [inpl_1() for _ in range(n - 1)]
queries = [inpl_1() for _ in range(m)]
for (a, b) in ab:
	g[a].append(b)
	g[b].append(a)
dist = [-1] * n
dist[0] = 0
p = [-1] * n
q = deque([0])
while q:
	now = q.popleft()
	for v in g[now]:
		if dist[v] == -1:
			dist[v] = dist[now] + 1
			p[v] = now
			q.append(v)
doub = [[-1] * n for _ in range(20)]
for i in range(n):
	doub[0][i] = p[i]
for k in range(1, 20):
	for i in range(n):
		pre = doub[k - 1][i]
		if pre == -1:
			continue
		doub[k][i] = doub[k - 1][pre]
for (_, *v) in queries:
	V = set()
	for u in v:
		V.add(0 if u == 0 else p[u])
	(dep_v, depth) = (-1, -1)
	V = list(V)
	for u in V:
		if dist[u] > depth:
			depth = dist[u]
			dep_v = u
	for u in V:
		dif = depth - dist[u]
		now = dep_v
		for digit in range(20)[::-1]:
			c = pow(2, digit)
			if dif >= c:
				now = doub[digit][now]
				dif -= c
		if now != u:
			print('NO')
			break
	else:
		print('YES')


import sys
from array import array
from typing import List, Tuple, TypeVar, Generic, Sequence, Union

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def main():
	(n, m) = map(int, input().split())
	adj = [[] for _ in range(n)]
	for (u, v) in (map(int, input().split()) for _ in range(n - 1)):
		adj[u - 1].append(v - 1)
		adj[v - 1].append(u - 1)
	time = 0
	(tin, tout, depth, par) = ([-1] * n, [-1] * n, [0] * n, [0] * n)
	ei = [0] * n
	stack = [0]
	while stack:
		v = stack.pop()
		time += 1
		if tin[v] == -1:
			tin[v] = time
		for (i, dest) in enumerate(adj[v][ei[v]:], start=ei[v]):
			if par[v] == dest:
				continue
			par[dest] = v
			depth[dest] = depth[v] + 1
			ei[v] = i + 1
			stack.append(v)
			stack.append(dest)
			break
		else:
			tout[v] = time
	ans = ['NO'] * m
	for (i, (_, *vertices)) in enumerate((tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(m))):
		v = max(vertices, key=lambda x: depth[x])
		if all((tin[par[u]] <= tin[v] <= tout[par[u]] for u in vertices)):
			ans[i] = 'YES'
	sys.stdout.buffer.write('\n'.join(ans).encode('utf-8'))
main()


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
g = [[] for i in range(n)]
for _ in range(n - 1):
	(u, v) = map(int, input().split())
	g[u - 1].append(v - 1)
	g[v - 1].append(u - 1)
stack = [[-1, 0, 1]]
in_t = [0] * n
out_t = [0] * n
par = [-1] * n
clock = 0
while stack:
	(p, ver, state) = stack.pop()
	if state:
		clock += 1
		in_t[ver] = clock
		stack.append([par, ver, 0])
		for to in g[ver]:
			if to != p:
				par[to] = ver
				stack.append([ver, to, 1])
	else:
		out_t[ver] = clock
for _ in range(m):
	l = 0
	r = n - 1
	v = list(map(int, input().split()))[1:]
	for vv in v:
		vv -= 1
		if vv != 0:
			vv = par[vv]
		l = max(l, in_t[vv])
		r = min(r, out_t[vv])
	if l <= r:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
(n, q) = map(int, input().split())
adj = [[] for i in range(n + 1)]
for i in range(n - 1):
	(u, v) = map(int, input().split())
	adj[u].append(v)
	adj[v].append(u)
parent = {1: 1}
in_time = [0] * (n + 1)
out_time = [0] * (n + 1)
stack = [(1, 0)]
cnt = 0
while stack:
	(node, visited) = stack.pop()
	if not visited:
		cnt += 1
		in_time[node] = cnt
		stack.append((node, 1))
		for v in adj[node]:
			if v not in parent:
				parent[v] = node
				stack.append((v, 0))
	else:
		out_time[node] = cnt
for i in range(q):
	query = list(map(int, input().split()))[1:]
	(low, high) = (1, n)
	for i in query:
		(low, high) = (max(low, in_time[parent[i]]), min(high, out_time[parent[i]]))
	print('YES' if low <= high else 'NO')


from sys import stdin, stdout
tree = []
parent = []
go_in = []
go_out = []
d = []

def main():
	global tree
	global parent
	global go_in
	global go_out
	global d
	(n, k) = list(map(int, stdin.readline().split()))
	tree = [[] for _ in range(n + 1)]
	parent = [0] * (n + 1)
	go_in = [0] * (n + 1)
	go_out = [0] * (n + 1)
	d = [0] * (n + 1)
	for _ in range(n - 1):
		(a, b) = list(map(int, stdin.readline().split()))
		tree[a].append(b)
		tree[b].append(a)
	stack = []
	stack.append(1)
	parent[1] = 1
	d[1] = 1
	while stack:
		x = stack.pop()
		for y in tree[x]:
			if parent[y] == 0:
				parent[y] = x
				d[y] = d[x] + 1
				stack.append(y)
	stack = []
	stack.append(1)
	kk = 1
	while stack:
		x = stack[-1]
		if go_in[x] == 0:
			go_in[x] = kk
			kk += 1
		is_another = False
		while tree[x]:
			y = tree[x].pop()
			if go_in[y] == 0:
				stack.append(y)
				is_another = True
				break
		if is_another:
			continue
		go_out[x] = kk
		kk += 1
		stack.pop()
	for _ in range(k):
		branch = 1
		mx = -1
		arr = list(map(int, stdin.readline().split()))
		is_ok = True
		for i in range(1, len(arr)):
			if d[arr[i]] > mx:
				mx = d[arr[i]]
				branch = parent[arr[i]]
		for i in range(1, len(arr)):
			cur = parent[arr[i]]
			if go_in[branch] <= go_in[cur] and go_out[branch] >= go_out[cur] or (go_in[branch] >= go_in[cur] and go_out[branch] <= go_out[cur]):
				continue
			is_ok = False
			stdout.write('NO\n')
			break
		if is_ok:
			stdout.write('YES\n')
main()


def DFS(graph, root, parent):
	dist = [-1] * (n + 1)
	dist[root] = 0
	stack = [root]
	while stack:
		x = stack.pop()
		for y in graph[x]:
			if dist[y] == -1:
				parent[y] = x
				dist[y] = dist[x] + 1
				stack.append(y)
	return dist

class Doubling:

	def __init__(self, graph, root):
		self.root = root
		n = len(graph) - 1
		self.ancestor_ls = [[0] * (n + 1)]
		self.distance = DFS(graph, root, self.ancestor_ls[0])
		self.bitn = n.bit_length()
		for i in range(1, self.bitn + 1):
			ancestor_ls_app = [0] * (n + 1)
			for j in range(1, n + 1):
				ancestor_ls_app[j] = self.ancestor_ls[i - 1][self.ancestor_ls[i - 1][j]]
			self.ancestor_ls.append(ancestor_ls_app)

	def dist(self):
		return self.distance

	def parent(self):
		return self.ancestor_ls[0]

	def ancestor(self, v, depth):
		if depth == 0:
			return v
		if n < depth:
			return self.root
		ret = v
		for i in range(self.bitn):
			if depth & 1 << i:
				ret = self.ancestor_ls[i][ret]
		return ret

	def LCA(self, u, v):
		if self.distance[u] < self.distance[v]:
			(u, v) = (v, u)
		dif = self.distance[u] - self.distance[v]
		w = self.ancestor(u, dif)
		if w == v:
			return v
		for i in range(self.bitn, -1, -1):
			if self.ancestor_ls[i][w] != self.ancestor_ls[i][v]:
				(w, v) = (self.ancestor_ls[i][w], self.ancestor_ls[i][v])
		return self.ancestor_ls[0][v]
import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n - 1)]
graph = [[] for i in range(n + 1)]
for (a, b) in ab:
	graph[a].append(b)
	graph[b].append(a)
sol = Doubling(graph, 1)
par = sol.parent()
d = sol.dist()
for _ in range(m):
	(k, *ls) = map(int, input().split())
	dmax = 0
	dmind = 0
	for i in range(k):
		ls[i] = par[ls[i]]
		if d[ls[i]] >= dmax:
			dmax = d[ls[i]]
			dmind = ls[i]
	flg = 1
	for i in range(k):
		if sol.LCA(dmind, ls[i]) != ls[i]:
			flg = 0
			break
	if flg:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
pre = {1: 0}
tin = [0] * (n + 1)
outnum = [0] * (n + 1)
edge = [set() for _ in range(n + 1)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	edge[b].add(a)
	edge[a].add(b)
stack = [(1, 1)]
count = 0
while stack:
	(node, state) = stack.pop()
	if state:
		count += 1
		tin[node] = count
		stack.append((node, 0))
		for child in edge[node]:
			if child not in pre:
				pre[child] = node
				stack.append((child, 1))
	else:
		outnum[node] = count
for _ in range(m):
	(l, r) = (1, n)
	q = list(map(int, input().split()))[1:]
	for query in q:
		if query != 1:
			query = pre[query]
		(l, r) = (max(l, tin[query]), min(r, outnum[query]))
	print('YES' if l <= r else 'NO')


import sys
input = sys.stdin.readline
(n, m) = [int(i) for i in input().split()]
graph = [[] for i in range(n)]
temp = 0
for j in range(n - 1):
	(uu, vv) = [int(i) - 1 for i in input().split()]
	graph[uu].append(vv)
	graph[vv].append(uu)
parent = [0] * n
tin = [0] * n
tout = [0] * n
stack = [(0, 0)]
cnt = 0
while stack:
	(curr, state) = stack.pop()
	if state == 0:
		stack.append((curr, 1))
		cnt += 1
		tin[curr] = cnt
		for child in graph[curr]:
			if child != parent[curr]:
				parent[child] = curr
				stack.append((child, 0))
	else:
		tout[curr] = cnt
for j in range(m):
	q = [int(i) - 1 for i in input().split()]
	q = q[1:]
	for i in range(len(q)):
		q[i] = parent[q[i]]
	cin = 1
	cout = n
	for i in q:
		cin = max(cin, tin[i])
		cout = min(cout, tout[i])
	if cin > cout:
		print('NO')
	else:
		print('YES')


from __future__ import print_function
from collections import Counter, OrderedDict
from itertools import permutations as perm
from fractions import Fraction
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
from math import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')

class rmq:

	def __init__(self, a):
		tab = [a.copy()]
		n = int(log2(len(a)))
		while len(tab) <= n:
			d = 1 << len(tab) - 1
			temp = []
			i = 0
			while i + d < len(tab[-1]):
				temp.append(min(tab[-1][i], tab[-1][i + d]))
				i += 1
			tab.append(temp)
		self.tab = tab

	def query(self, l, r):
		d = int(log2(r - l + 1))
		x = r + 1 - (1 << d)
		return min(self.tab[d][l], self.tab[d][x])

class lca:

	def __init__(self, adj, n):
		eur = []
		stack = [1]
		(getId, getNode) = ([0] * (n + 1), [0] * (n + 1))
		idx = [0] * (1 + n)
		cId = 1
		while stack:
			p = stack[-1]
			if getId[p] == 0:
				getId[p] = cId
				getNode[cId] = p
				cId += 1
				idx[p] = len(eur)
			eur.append(getId[p])
			if adj[p] and getId[adj[p][-1]]:
				adj[p].pop()
			elif adj[p]:
				stack.append(adj[p].pop())
			else:
				stack.pop()
		self.rmq_ = rmq(eur)
		(self.getNode, self.getId) = (getNode, getId)
		self.idx = idx

	def query(self, l, r):
		(l, r) = (self.idx[l], self.idx[r])
		if r < l:
			(l, r) = (r, l)
		p = self.getNode[self.rmq_.query(l, r)]
		return p

def getDepth(adj, n):
	stack = [1]
	d = [0] * (n + 1)
	d[1] = 1
	while stack:
		p = stack.pop()
		for c in adj[p]:
			if d[c] == 0:
				stack.append(c)
				d[c] = d[p] + 1
	return d

def getParent(adj, n, depth):
	par = [1] * (n + 1)
	for c in range(2, n + 1):
		for p in adj[c]:
			if depth[p] < depth[c]:
				par[c] = p
				break
	return par
(n, q) = gil()
adj = [[] for _ in range(n + 1)]
for _ in range(n - 1):
	(x, y) = gil()
	adj[x].append(y)
	adj[y].append(x)
depth = getDepth(adj, n)
parent = getParent(adj, n, depth)
lca_ = lca(adj, n)
for _ in range(q):
	q_ = gil()[1:]
	l = max(q_, key=lambda x: depth[x])
	ans = 'YES'
	for r in q_:
		r = parent[r]
		p = lca_.query(l, r)
		if p != r:
			ans = 'NO'
			break
	print(ans)


from sys import setrecursionlimit, stdin, stdout
setrecursionlimit(200179)

def DFS():
	stack1 = [[-1, 0], [0, 0]]
	while len(stack1) > 1:
		(vertex, q1) = stack1[-1]
		(height[vertex], parents[vertex]) = (len(stack1) - 1, stack1[-2][0])
		for q in range(q1, len(d[vertex])):
			if d[vertex][q] != stack1[-2][0]:
				stack1[-1][1] = q + 1
				stack1.append([d[vertex][q], 0])
				break
		else:
			stack1.pop()

def DFS1():
	(ans, naw) = ([True] * m, [True] * n)
	naw[0] = False
	stack1 = [[-1, 0], [0, 0]]
	was = [True, True]
	while len(stack1) > 1:
		(vertex, q1) = stack1[-1]
		if was[-1]:
			for q in d[vertex]:
				naw[q] = False
			for q in quest[vertex]:
				for q2 in q[0]:
					if naw[q2]:
						ans[q[1]] = False
						break
		was[-1] = False
		(height[vertex], parents[vertex]) = (len(stack1) - 1, stack1[-2][0])
		for q in range(q1, len(d[vertex])):
			if d[vertex][q] != stack1[-2][0]:
				stack1[-1][1] = q + 1
				was.append(True)
				stack1.append([d[vertex][q], 0])
				break
		else:
			for q in d[vertex]:
				naw[q] = True
			naw[stack1[-2][0]] = False
			stack1.pop()
	return ans

def main():
	input = stdin.readline
	for q in range(n - 1):
		(x, y) = map(int, input().split())
		d[x - 1].append(y - 1)
		d[y - 1].append(x - 1)
	DFS()
	for q in range(m):
		a = list(map(lambda x: int(x) - 1, input().split()))[1:]
		max1 = [-1, -1]
		for q1 in a:
			if max1[1] < height[q1]:
				max1 = [parents[q1], height[q1]]
		quest[max1[0]].append([a, q])
	ans = DFS1()
	stdout.write('\n'.join(map(lambda x: 'YES' if x else 'NO', ans)))
(n, m) = map(int, input().split())
(parents, height) = ([0] * n, [0] * n)
d = [[] for q in range(n)]
quest = [[] for q in range(n)]
main()


import os
import sys
if os.path.exists('/mnt/c/Users/Square/square/codeforces'):
	f = iter(open('E.txt').readlines())

	def input():
		return next(f)
else:
	input = lambda : sys.stdin.readline().strip()
fprint = lambda *args: print(*args, flush=True)
(n, m) = map(int, input().split())
g = {i: [] for i in range(n + 1)}
for _ in range(n - 1):
	(u, v) = map(int, input().split())
	g[u].append(v)
	g[v].append(u)
stack = [1]
fr = [0] * (n + 1)
fr[1] = 1
ins = [-1] * (n + 1)
outs = [-1] * (n + 1)
t = 0
while stack:
	u = stack[-1]
	if ins[u] == -1:
		ins[u] = t
		for v in g[u]:
			if fr[v] == 0:
				fr[v] = u
				stack.append(v)
	else:
		outs[u] = t
		stack.pop()
	t += 1
for _ in range(m):
	path = list(map(int, input().split()))[1:]
	vs = [fr[i] for i in path]
	segments = sorted([(ins[i], outs[i]) for i in vs])
	if len(segments) == 1:
		print('YES')
	else:
		bad = False
		for i in range(len(segments) - 1):
			if segments[i][1] < segments[i + 1][1]:
				print('NO')
				bad = True
				break
		if not bad:
			print('YES')


def main():
	import sys
	input = sys.stdin.buffer.readline

	def STfunc(a, b):
		if a < b:
			return a
		else:
			return b

	class SparseTable:

		def __init__(self, A):
			self.N = len(A)
			self.K = self.N.bit_length() - 1
			self.table = [[0] * (self.K + 1) for _ in range(self.N)]
			for (i, a) in enumerate(A):
				self.table[i][0] = a
			for k in range(1, self.K + 1):
				for i in range(self.N):
					j = i + (1 << k - 1)
					if j <= self.N - 1:
						self.table[i][k] = STfunc(self.table[i][k - 1], self.table[j][k - 1])
					else:
						self.table[i][k] = self.table[i][k - 1]

		def query(self, l, r):
			k = (r - l).bit_length() - 1
			return STfunc(self.table[l][k], self.table[r - (1 << k)][k])

	def EulerTour(adj, root):
		st = [root]
		ret = []
		seen = [0] * len(adj)
		par = [0] * len(adj)
		depth = [0] * len(adj)
		while st:
			v = st.pop()
			if seen[v]:
				ret.append(v)
				continue
			ret.append(v)
			seen[v] = 1
			if par[v] != 0:
				st.append(par[v])
			for u in adj[v]:
				if seen[u] == 0:
					st.append(u)
					par[u] = v
					depth[u] = depth[v] + 1
		return (ret, depth)
	(N, M) = map(int, input().split())
	adj = [[] for _ in range(N + 1)]
	for _ in range(N - 1):
		(a, b) = map(int, input().split())
		adj[a].append(b)
		adj[b].append(a)
	(et, depth) = EulerTour(adj, 1)
	depth_list = [0] * len(et)
	left = [-1] * (N + 1)
	right = [-1] * (N + 1)
	for (i, v) in enumerate(et):
		depth_list[i] = depth[v]
		if left[v] < 0:
			left[v] = i
		right[v] = i
	ST = SparseTable(depth_list)
	for _ in range(M):
		v_list = list(map(int, input().split()))
		vd = [(v, depth[v]) for v in v_list[1:]]
		vd.sort(key=lambda x: x[1])
		ok = 1
		L = len(vd)
		for i in range(L - 1):
			(a, da) = vd[i]
			(b, db) = vd[i + 1]
			lca_depth = ST.query(min(left[a], left[b]), max(right[a], right[b]) + 1)
			if lca_depth < min(da, db) - 1:
				ok = 0
				break
		if ok:
			print('YES')
		else:
			print('NO')
main()


from sys import stdin, gettrace
from collections import deque

def input():
	return stdin.buffer.readline()

def readTree(n):
	adj = [set() for _ in range(n)]
	for _ in range(n - 1):
		(u, v) = map(int, input().split())
		adj[u - 1].add(v - 1)
		adj[v - 1].add(u - 1)
	return adj

def euler_dfs(n, adj):
	parent = [None] * n
	depth = [-1] * n
	depth[0] = 0
	stack = [(0, adj[0])]
	eulerfirst = [-1] * n
	eulerlast = [-1] * n
	eindex = 0
	while stack:
		(p, aa) = stack.pop()
		if eulerfirst[p] == -1:
			eulerfirst[p] = eindex
		eulerlast[p] = eindex
		eindex += 1
		for c in aa:
			if c != parent[p]:
				parent[c] = p
				depth[c] = depth[p] + 1
				stack.append((p, []))
				stack.append((c, adj[c]))
	return (eulerfirst, eulerlast, parent, depth)

def main():
	(n, m) = map(int, input().split())
	adj = readTree(n)
	(ef, el, parent, depth) = euler_dfs(n, adj)

	def solve():
		vv = [int(a) - 1 for a in input().split()]
		vv = vv[1:]
		vv.sort(key=lambda v: depth[v])
		vvp = [v if v == 0 else parent[v] for v in vv]
		for (vp, v) in zip(vvp, vvp[1:]):
			if ef[v] < ef[vp] or el[v] > el[vp]:
				print('NO')
				return
		print('YES')
	for _ in range(m):
		solve()
main()


def dfs(graph, start=0):
	n = len(graph)
	visited = [False] * n
	(t_in, t_out, parent) = ([0] * n, [0] * n, [0] * n)
	t = 0
	stack = [start]
	while stack:
		t += 1
		start = stack[-1]
		if not visited[start]:
			visited[start] = True
			t_in[start] = t
			for child in graph[start]:
				if not visited[child]:
					parent[child] = start
					stack.append(child)
		else:
			stack.pop()
			t_out[start] = t
	return (t_in, t_out, parent)

def main():
	(n, m) = map(int, input().split())
	e = [[] for _ in range(n + 1)]
	for _ in range(n - 1):
		(u, v) = map(int, input().split())
		e[u].append(v)
		e[v].append(u)
	e[0].append(1)
	e[1].append(0)
	(t_in, t_out, parent) = dfs(e)
	for _ in range(m):
		a = list(map(int, input().split()))[1:]
		a = [parent[x] for x in a]
		last = max(a, key=lambda x: t_in[x])
		for x in a:
			if t_out[x] < t_out[last]:
				print('NO')
				break
		else:
			print('YES')
import sys

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


(n, m) = map(int, input().split())
edges = (map(int, input().split()) for _ in range(n - 1))
g = [[] for _ in range(n + 1)]
for (u, v) in edges:
	g[u].append(v)
	g[v].append(u)
depths = [-1] * (n + 1)
depths[1] = 0
par = [-1] * (n + 1)
tin = [-1] * (n + 1)
tout = [-1] * (n + 1)
stack = [1]
cnt = 0
while stack:
	node = stack.pop()
	if node < 0:
		tout[-node] = cnt
		cnt += 1
		continue
	stack.append(-node)
	tin[node] = cnt
	cnt += 1
	for v in g[node]:
		if depths[v] == -1:
			depths[v] = depths[node] + 1
			par[v] = node
			stack.append(v)
ans = []
for _ in range(m):
	ks = map(int, input().split())
	p = 1
	next(ks)
	for u in sorted(set(map(par.__getitem__, ks)) - {-1, 1}, key=depths.__getitem__):
		if not (tin[p] < tin[u] and tout[p] > tout[u]):
			ans.append('NO')
			break
		p = u
	else:
		ans.append('YES')
print('\n'.join(ans))


from heapq import *
from collections import deque
import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def MI1():
	return map(int1, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LI1():
	return list(map(int1, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():

	def dfs():
		stack = [(0, -1, 1)]
		while stack:
			(u, pu, d) = stack.pop()
			dep[u] = d
			for v in to[u]:
				if v == pu:
					continue
				anc[0][v] = u
				stack.append((v, u, d + 1))

	def ok():
		(pd, pu) = du[0]
		for (d, u) in du[1:]:
			dist = pd - d
			lv = 0
			while dist:
				if dist & 1:
					pu = anc[lv][pu]
				lv += 1
				dist >>= 1
			if u != pu and anc[0][u] != anc[0][pu]:
				return False
			(pd, pu) = (d, u)
		return True
	(n, m) = MI()
	to = [[] for _ in range(n)]
	for _ in range(n - 1):
		(u, v) = MI1()
		to[u].append(v)
		to[v].append(u)
	mxlv = (n - 1).bit_length()
	anc = [[0] * n for _ in range(mxlv)]
	dep = [-1] * n
	dfs()
	alv1 = anc[0]
	for lv in range(1, mxlv):
		alv = anc[lv]
		for u in range(n):
			alv[u] = alv1[alv1[u]]
		alv1 = alv
	for _ in range(m):
		du = [(dep[u], u) for u in LI1()[1:]]
		du.sort(reverse=True)
		if ok():
			print('YES')
		else:
			print('NO')
main()


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
pre = {1: 0}
tin = [0] * (n + 1)
om = [0] * (n + 1)
ee = [set() for _ in range(n + 1)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	ee[b].add(a)
	ee[a].add(b)
sk = [(1, 1)]
cnt = 0
while sk:
	(ne, se) = sk.pop()
	if se:
		cnt += 1
		tin[ne] = cnt
		sk.append((ne, 0))
		for child in ee[ne]:
			if child not in pre:
				pre[child] = ne
				sk.append((child, 1))
	else:
		om[ne] = cnt
for _ in range(m):
	(l, r) = (1, n)
	q = list(map(int, input().split()))[1:]
	for qy in q:
		if qy != 1:
			qy = pre[qy]
		(l, r) = (max(l, tin[qy]), min(r, om[qy]))
	print('YES' if l <= r else 'NO')


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
parent = {1: 0}
inVertex = [0] * (n + 1)
outVertex = [0] * (n + 1)
graph = [set() for _ in range(n + 1)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	graph[b].add(a)
	graph[a].add(b)
stack = [(1, 1)]
count = 0
while stack:
	(node, state) = stack.pop()
	if state:
		inVertex[node] = count = count + 1
		stack.append((node, 0))
		for nextnode in graph[node]:
			if nextnode not in parent:
				parent[nextnode] = node
				stack.append((nextnode, 1))
	else:
		outVertex[node] = count
for _ in range(m):
	(left, right) = (1, n)
	querylist = list(map(int, input().split()))[1:]
	for query in querylist:
		if query != 1:
			query = parent[query]
		(left, right) = (max(left, inVertex[query]), min(right, outVertex[query]))
	print('YES' if left <= right else 'NO')


from collections import deque
import sys
input = sys.stdin.readline

def bfs(s):
	q = deque()
	q.append(s)
	dist = [-1] * (n + 1)
	dist[s] = 0
	parent = [-1] * (n + 1)
	while q:
		i = q.popleft()
		d = dist[i] + 1
		for j in G[i]:
			if dist[j] == -1:
				dist[j] = d
				q.append(j)
				parent[j] = i
	return (dist, parent)
(n, m) = map(int, input().split())
G = [[] for _ in range(n + 1)]
for _ in range(n - 1):
	(u, v) = map(int, input().split())
	G[u].append(v)
	G[v].append(u)
(dist, parent) = bfs(1)
dp = []
dp0 = list(parent)
ok = 1
while ok:
	ok = 0
	dp1 = [-1] * (n + 1)
	for i in range(1, n + 1):
		if dp0[i] ^ -1:
			dp1[i] = dp0[dp0[i]]
			if dp1[i] ^ -1:
				ok = 1
	dp.append(dp0)
	dp0 = dp1
for _ in range(m):
	v = list(map(int, input().split()))
	md = -1
	u = []
	for i in range(1, len(v)):
		vi = v[i]
		if vi == 1:
			continue
		p = parent[vi]
		u.append(p)
		if md < dist[p]:
			md = dist[p]
			s = p
	ans = 'YES'
	for i in u:
		di = dist[i]
		d = md - di
		(j, p) = (0, 1)
		t = s
		while d:
			if d & p:
				t = dp[j][t]
				d -= p
			j += 1
			p *= 2
		if i ^ t:
			ans = 'NO'
			break
	print(ans)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
EDGELIST = [[] for i in range(n + 1)]
for i in range(n - 1):
	(x, y) = map(int, input().split())
	EDGELIST[x].append(y)
	EDGELIST[y].append(x)
DEPTH = [-1] * (n + 1)
DEPTH[1] = 0
from collections import deque
QUE = deque([1])
QUE2 = deque()
EULER = []
USED = [0] * (n + 1)
P = [-1] * (n + 1)
P[1] = 1
while QUE:
	x = QUE.pop()
	EULER.append((DEPTH[x], x))
	if USED[x] == 1:
		continue
	for to in EDGELIST[x]:
		if USED[to] == 0:
			DEPTH[to] = DEPTH[x] + 1
			P[to] = x
			QUE2.append(to)
		else:
			QUE.append(to)
	QUE.extend(QUE2)
	QUE2 = deque()
	USED[x] = 1
MINP = [1 << 30] * (n + 1)
MAXP = [-1] * (n + 1)
for (ind, (depth, p)) in enumerate(EULER):
	MINP[p] = min(MINP[p], ind)
	MAXP[p] = max(MAXP[p], ind)
LEN = len(EULER)
seg_el = 1 << LEN.bit_length()
SEG = [(1 << 30, 0)] * (2 * seg_el)
for i in range(LEN):
	SEG[i + seg_el] = EULER[i]
for i in range(seg_el - 1, 0, -1):
	SEG[i] = min(SEG[i * 2], SEG[i * 2 + 1])

def update(n, x, seg_el):
	i = n + seg_el
	SEG[i] = x
	i >>= 1
	while i != 0:
		SEG[i] = min(SEG[i * 2], SEG[i * 2 + 1])
		i >>= 1

def getvalues(l, r):
	L = l + seg_el
	R = r + seg_el
	ANS = (1 << 30, 0)
	while L < R:
		if L & 1:
			ANS = min(ANS, SEG[L])
			L += 1
		if R & 1:
			R -= 1
			ANS = min(ANS, SEG[R])
		L >>= 1
		R >>= 1
	return ANS

def LCA(l, r):
	return getvalues(min(MINP[l], MINP[r]), max(MAXP[l], MAXP[r]) + 1)
for i in range(m):
	A = list(map(int, input().split()))[1:]
	M = max(A, key=lambda x: DEPTH[x])
	for a in A:
		if LCA(M, P[a])[1] == P[a]:
			continue
		else:
			sys.stdout.write('NO\n')
			break
	else:
		sys.stdout.write('YES\n')


import sys
input = sys.stdin.readline
(N, Q) = map(int, input().split())
G = [set() for _ in range(N + 1)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	G[a].add(b)
	G[b].add(a)
S = [None] * (2 * N - 1)
F = [None] * (N + 1)
stack = [1]
visited = set()
depth = [None] * (N + 1)
depth[1] = 0
path = []
ii = 0
while stack:
	v = stack.pop()
	if v > 0:
		visited.add(v)
		path.append(v)
		(F[v], S[ii]) = (ii, v)
		ii += 1
		for u in G[v]:
			if u in visited:
				continue
			stack += [-v, u]
			depth[u] = depth[v] + 1
	else:
		child = path.pop()
		S[ii] = -v
		ii += 1
INF = (N, None)
M = 2 * N
M0 = 2 ** (M - 1).bit_length()
data = [INF] * (2 * M0)
for (i, v) in enumerate(S):
	data[M0 - 1 + i] = (depth[abs(v)], i)
for i in range(M0 - 2, -1, -1):
	data[i] = min(data[2 * i + 1], data[2 * i + 2])

def _query(a, b):
	yield INF
	(a, b) = (a + M0, b + M0)
	while a < b:
		if b & 1:
			b -= 1
			yield data[b - 1]
		if a & 1:
			yield data[a - 1]
			a += 1
		(a, b) = (a >> 1, b >> 1)

def query(u, v):
	(fu, fv) = (F[u], F[v])
	if fu > fv:
		(fu, fv) = (fv, fu)
	return abs(S[min(_query(fu, fv + 1))[1]])

def dist(x, y):
	c = query(x, y)
	return depth[x] + depth[y] - 2 * depth[c]
for _ in range(Q):
	X = list(map(int, input().split()))[1:]
	x = X[0]
	for y in X[1:]:
		c = query(x, y)
		if depth[x] < depth[y]:
			(u, v) = (x, y)
		else:
			(u, v) = (y, x)
		if depth[u] - depth[c] > 1:
			print('NO')
			break
		x = v
	else:
		print('YES')


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
pre = {1: 0}
innum = [0] * (n + 1)
outnum = [0] * (n + 1)
edge = [set() for _ in range(n + 1)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	edge[b].add(a)
	edge[a].add(b)
stack = [(1, 1)]
count = 0
while stack:
	(node, state) = stack.pop()
	if state:
		innum[node] = count = count + 1
		stack.append((node, 0))
		for nextnode in edge[node]:
			if nextnode not in pre:
				pre[nextnode] = node
				stack.append((nextnode, 1))
	else:
		outnum[node] = count
for _ in range(m):
	(left, right) = (1, n)
	querylist = list(map(int, input().split()))[1:]
	for query in querylist:
		if query != 1:
			query = pre[query]
		(left, right) = (max(left, innum[query]), min(right, outnum[query]))
	print('YES' if left <= right else 'NO')


from collections import defaultdict, deque
from sys import stdin, stdout
time_in = {}
time_out = {}
time = 0
parents = {}
depth_table = {}
(n, m) = map(int, stdin.readline().split(' '))
graph = defaultdict(list)

def dfs(root):
	global time
	visited = set()
	stack = [(root, 0, -1, False)]
	while stack:
		(node, depth, parent, finished) = stack.pop()
		if not finished:
			visited.add(node)
			time_in[node] = time
			time += 1
			depth_table[node] = depth
			parents[node] = parent
			stack.append((node, depth, parent, True))
			for neigh in graph[node]:
				if neigh not in visited:
					stack.append((neigh, depth + 1, node, False))
		else:
			time_out[node] = time
			time += 1

def is_ancestor(path, furth):
	return time_in[path] <= time_in[furth] and time_out[furth] <= time_out[path]
for _ in range(n - 1):
	(u, v) = map(int, stdin.readline().split(' '))
	graph[u - 1].append(v - 1)
	graph[v - 1].append(u - 1)
dfs(0)
for _ in range(m):
	(k, *vertices) = list(map(int, stdin.readline().split(' ')))
	for i in range(k):
		if parents[vertices[i] - 1] != -1:
			vertices[i] = parents[vertices[i] - 1]
		else:
			vertices[i] -= 1
	furthest = max(vertices, key=lambda x: depth_table[x])
	running_check = True
	for v in vertices:
		running_check &= is_ancestor(v, furthest)
		if not running_check:
			stdout.write('NO\n')
			break
	if running_check:
		stdout.write('YES\n')


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from heapq import *
from math import gcd, factorial, floor, ceil
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 10 ** 9 + 7

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

class RangeQuery:

	def __init__(self, data, func=min):
		self.func = func
		self._data = _data = [list(data)]
		(i, n) = (1, len(_data[0]))
		while 2 * i <= n:
			prev = _data[-1]
			_data.append([func(prev[j], prev[j + i]) for j in range(n - 2 * i + 1)])
			i <<= 1

	def query(self, begin, end):
		depth = (end - begin).bit_length() - 1
		return self.func(self._data[depth][begin], self._data[depth][end - (1 << depth)])

class LCA:

	def __init__(self, root, graph):
		self.time = [-1] * len(graph)
		self.path = [-1] * len(graph)
		P = [-1] * len(graph)
		t = -1
		dfs = [root]
		while dfs:
			node = dfs.pop()
			self.path[t] = P[node]
			self.time[node] = t = t + 1
			for nei in graph[node]:
				if self.time[nei] == -1:
					P[nei] = node
					dfs.append(nei)
		self.rmq = RangeQuery((self.time[node] for node in self.path))

	def __call__(self, a, b):
		if a == b:
			return a
		a = self.time[a]
		b = self.time[b]
		if a > b:
			(a, b) = (b, a)
		return self.path[self.rmq.query(a, b)]

@iterative
def dfs(v, visited, st, new, depth, par):
	new.append(st)
	visited[st] = 1
	for i in v[st]:
		if visited[i] == 0:
			par[i] = st
			depth[i] = depth[st] + 1
			ok = (yield dfs(v, visited, i, new, depth, par))
	yield True

def solve(case):
	(n, q) = sep()
	g = [[] for i in range(n)]
	for i in range(n - 1):
		(a, b) = sep()
		a -= 1
		b -= 1
		g[a].append(b)
		g[b].append(a)
	depth = [0] * n
	par = [-1] * n
	vis = [False] * n
	dfs(g, vis, 0, [], depth, par)
	lca = LCA(0, g)
	for i in range(q):
		k = lis()
		k = k[1:]
		k = sorted(k, key=lambda x: depth[x - 1])[::-1]
		for ii in range(len(k)):
			k[ii] -= 1
		f = True
		chck = k[0]
		for ii in range(1, len(k)):
			if lca(chck, k[ii]) == chck or lca(chck, k[ii]) == k[ii]:
				continue
			elif lca(chck, par[k[ii]]) == chck or lca(chck, par[k[ii]]) == par[k[ii]]:
				continue
			else:
				print('NO')
				f = False
				break
		if f:
			print('YES')
testcase(1)


import sys
input = sys.stdin.readline
from collections import defaultdict
from collections import deque
from enum import Enum
(nodes, queries) = map(int, input().split())
graph = defaultdict(list)
height = [0] * (nodes + 1)
in_time = [0] * (nodes + 1)
out_time = [0] * (nodes + 1)
parent = [1] * (nodes + 1)

class Color(Enum):
	WHITE = 0
	GRAY = 1
	BLACK = 2
color = [Color.WHITE] * (nodes + 1)
for _ in range(1, nodes):
	(u, v) = map(int, input().split())
	graph[u].append(v)
	graph[v].append(u)

def dfs(root):
	stack = deque()
	time = 0
	stack.append(root)
	while stack:
		node = stack.pop()
		if color[node] == Color.WHITE:
			time += 1
			in_time[node] = time
			color[node] = Color.GRAY
			stack.append(node)
			for neighbor in graph[node]:
				if color[neighbor] == Color.WHITE:
					height[neighbor] = height[node] + 1
					parent[neighbor] = node
					stack.append(neighbor)
		elif color[node] == Color.GRAY:
			time += 1
			out_time[node] = time
			color[node] = Color.BLACK
dfs(1)

def is_ancestor(high, low):
	return in_time[high] <= in_time[low] and out_time[low] <= out_time[high]
for _ in range(queries):
	a = list(map(int, input().split()))[1:]
	parents = set()
	max_node = a[0]
	for node in a:
		if height[max_node] < height[node]:
			max_node = node
	for node in a:
		if node == max_node:
			continue
		if parent[node] not in parents:
			parents.add(parent[node])
	ok = True
	for node in parents:
		if not is_ancestor(node, max_node):
			ok = False
			break
	print('YES') if ok else print('NO')


import sys
input = lambda : sys.stdin.readline().rstrip()
(N, M) = map(int, input().split())
X = [[] for i in range(N)]
for i in range(N - 1):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	X[x].append(y)
	X[y].append(x)
P = [-1] * N
DE = [0] * N

def EulerTour(n, X, i0=0):
	Q = [~i0, i0]
	ct = -1
	ET = []
	ET1 = [0] * n
	ET2 = [0] * n
	de = -1
	while Q:
		i = Q.pop()
		if i < 0:
			ET2[~i] = ct
			de -= 1
			continue
		if i >= 0:
			ET.append(i)
			ct += 1
			if ET1[i] == 0:
				ET1[i] = ct
			de += 1
			DE[i] = de
		for a in X[i][::-1]:
			if a != P[i]:
				P[a] = i
				for k in range(len(X[a])):
					if X[a][k] == i:
						del X[a][k]
						break
				Q.append(~a)
				Q.append(a)
	return (ET, ET1, ET2)
(ET, ET1, ET2) = EulerTour(N, X, 0)
for _ in range(M):
	A = [max(P[int(a) - 1], 0) for a in input().split()][1:]
	mad = -1
	for a in A:
		if DE[a] > mad:
			mad = DE[a]
			maa = a
	e = ET1[maa]
	for a in A:
		if not ET1[a] <= e <= ET2[a]:
			print('NO')
			break
	else:
		print('YES')


import sys, math, os
from io import BytesIO, IOBase
from collections import defaultdict as dd, deque, Counter

def mdata():
	return list(map(int, data().split()))
mod = 998244353
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
data = lambda : sys.stdin.readline().rstrip('\r\n')
T = [0]

def main():

	@bootstrap
	def dfs(T, par, val, tin, tout, x, p=-1, cnt=0):
		tin[x] = T[0]
		val[x] = cnt
		T[0] += 1
		for i in g[x]:
			if i != p:
				yield dfs(T, par, val, tin, tout, i, x, cnt + 1)
		par[x] = p
		tout[x] = T[0]
		T[0] += 1
		yield
	(n, m) = mdata()
	g = [set() for i in range(n)]
	for i in range(n - 1):
		(a, b) = mdata()
		g[a - 1].add(b - 1)
		g[b - 1].add(a - 1)
	tin = [0] * n
	tout = [0] * n
	par = [0] * n
	val = [0] * n
	dfs(T, par, val, tin, tout, 0)
	for i in range(m):
		l = list(mdata())
		flag = True
		max1 = 0
		ind = 0
		for j in l[1:]:
			if val[j - 1] > max1:
				max1 = val[j - 1]
				ind = j - 1
		for j in l[1:]:
			if j - 1 != ind and j != 1:
				if tin[par[j - 1]] < tin[ind] and tout[par[j - 1]] > tout[ind]:
					continue
				flag = False
				break
		if flag == True:
			print('YES')
		else:
			print('NO')
main()


import sys
input = sys.stdin.buffer.readline
(n, m) = map(int, input().split())
graph = [[] for i in range(n + 1)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	graph[a].append(b)
	graph[b].append(a)
tin = [0 for i in range(n + 1)]
tout = [0] * (n + 1)
parent = [1 for i in range(n + 1)]
stack = [[1, 0]]
cnt = 0
while stack:
	(curr, state) = stack.pop()
	if state == 0:
		stack.append((curr, 1))
		cnt += 1
		tin[curr] = cnt
		for child in graph[curr]:
			if child != parent[curr]:
				parent[child] = curr
				stack.append((child, 0))
	else:
		tout[curr] = cnt
for j in range(m):
	q = [int(i) for i in input().split()]
	q = q[1:]
	for i in range(len(q)):
		q[i] = parent[q[i]]
	cin = 1
	cout = n
	for i in q:
		cin = max(cin, tin[i])
		cout = min(cout, tout[i])
	if cin > cout:
		print('NO')
	else:
		print('YES')


import io
import os
from collections import Counter, defaultdict, deque

class RangeMinQuery:

	def __init__(self, data):
		self._data = [list(data)]
		n = len(self._data[0])
		w = 1
		while 2 * w <= n:
			prev = self._data[-1]
			self._data.append([min(prev[j], prev[j + w]) for j in range(n - 2 * w + 1)])
			w *= 2

	def query(self, begin, end):
		assert begin < end
		depth = (end - begin).bit_length() - 1
		return min(self._data[depth][begin], self._data[depth][end - (1 << depth)])

class LCA:

	def __init__(self, graph, root=1):
		self.eulerTour = []
		self.preorder = [None] * len(graph)
		self.postorder = [None] * len(graph)
		self.depth = [None] * len(graph)
		self.parent = [None] * len(graph)
		stack = [root]
		self.depth[root] = 0
		self.parent[root] = None
		while stack:
			node = stack.pop()
			self.eulerTour.append(node)
			if self.preorder[node] is None:
				self.preorder[node] = len(self.eulerTour) - 1
				for nbr in graph[node]:
					if self.preorder[nbr] is None:
						self.depth[nbr] = self.depth[node] + 1
						self.parent[nbr] = node
						stack.append(node)
						stack.append(nbr)
			self.postorder[node] = len(self.eulerTour) - 1
		self.rmq = RangeMinQuery((self.preorder[node] for node in self.eulerTour))
		if False:
			assert self.depth[1] == 0
			assert self.parent[1] == None
			for node in range(1, len(graph)):
				assert self.preorder[node] == self.eulerTour.index(node)
				assert self.postorder[node] == max((i for (i, x) in enumerate(self.eulerTour) if x == node))
			for i in range(len(self.rmq._data)):
				for j in range(i + 1, len(self.rmq._data) + 1):
					assert min(self.rmq._data[0][i:j]) == self.rmq.query(i, j)
			for u in range(1, N + 1):
				for v in range(1, N + 1):
					assert self.lca(u, v) == self.lca(v, u)
					lca = self.lca(u, v)
					assert self.isAncestor(lca, u)
					assert self.isAncestor(lca, v)
					path = self.path(u, v)
					assert len(path) == self.dist(u, v) + 1
					for (x, y) in zip(path, path[1:]):
						assert y in graph[x]
					assert len(set(path)) == len(path)

	def lca(self, u, v):
		a = self.preorder[u]
		b = self.preorder[v]
		if a > b:
			(a, b) = (b, a)
		return self.eulerTour[self.rmq.query(a, b + 1)]

	def dist(self, u, v):
		return self.depth[u] + self.depth[v] - 2 * self.depth[self.lca(u, v)]

	def isAncestor(self, ancestor, v):
		return self.preorder[ancestor] <= self.preorder[v] and self.postorder[v] <= self.postorder[ancestor]

	def path(self, u, v):
		uPath = []
		while not self.isAncestor(u, v):
			uPath.append(u)
			u = self.parent[u]
		lca = u
		assert self.isAncestor(u, v)
		vPath = []
		while v != lca:
			vPath.append(v)
			v = self.parent[v]
		ret = uPath + [lca] + vPath[::-1]
		return ret

def solve(N, M, edges, queries):
	graph = [[] for i in range(N + 1)]
	for e in edges:
		graph[e[0]].append(e[1])
		graph[e[1]].append(e[0])
	tree = LCA(graph)
	ans = []
	for vertices in queries:
		parents = [tree.parent[v] for v in vertices if v != 1]
		bad = False
		if parents:
			deepestNode = max(parents, key=lambda v: tree.depth[v])
			for p in parents:
				if tree.lca(deepestNode, p) != p:
					bad = True
					break
		if bad:
			ans.append('NO')
		else:
			ans.append('YES')
	return '\n'.join(ans)
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(N, M) = [int(x) for x in input().split()]
edges = [[int(x) for x in input().split()] for i in range(N - 1)]
queries = [[int(x) for x in input().split()][1:] for i in range(M)]
ans = solve(N, M, edges, queries)
print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)

def ctd(chr):
	return ord(chr) - ord('a')
mod = 998244353
INF = float('inf')

def main():
	(n, m) = RL()
	gp = [[] for _ in range(n + 1)]
	for _ in range(n - 1):
		(f, t) = RL()
		gp[f].append(t)
		gp[t].append(f)
	q = [[1, 1]]
	vis = [0] * (n + 1)
	vis[1] = 1
	par = [1] * (n + 1)
	tag = 0
	tin = [0] * (n + 1)
	tout = [0] * (n + 1)
	while q:
		(nd, st) = q.pop()
		if st:
			q.append([nd, 0])
			tag += 1
			tin[nd] = tag
			for nex in gp[nd]:
				if vis[nex] == 1:
					continue
				par[nex] = nd
				q.append([nex, 1])
				vis[nex] = 1
		else:
			tout[nd] = tag
	for _ in range(m):
		qry = RLL()[1:]
		(l, r) = (1, n)
		for i in qry:
			now = par[i]
			(b, e) = (tin[now], tout[now])
			(l, r) = (max(l, b), min(e, r))
		print('YES' if l <= r else 'NO')
main()


class Doubling:

	def __init__(self, graph, rootNode=0):
		self.graph = graph
		self.N = len(graph)
		self.Log_N = (self.N - 1).bit_length()
		self.rootNode = rootNode
		self.prev = [None] * self.N
		self.Depth = [-1] * self.N
		q = [self.rootNode]
		self.Depth[self.rootNode] = 0
		d = 0
		while q:
			qq = []
			d += 1
			for p in q:
				for np in self.graph[p]:
					if self.Depth[np] == -1:
						self.prev[np] = p
						self.Depth[np] = d
						qq.append(np)
			q = qq
		self.kprev = [self.prev]
		S = self.prev
		for k in range(self.Log_N):
			T = [None] * self.N
			for i in range(self.N):
				if S[i] is None:
					continue
				T[i] = S[S[i]]
			self.kprev.append(T)
			S = T

	def LCAquery(self, u, v):
		dd = self.Depth[v] - self.Depth[u]
		if dd < 0:
			(u, v) = (v, u)
			dd = -dd
		for k in range(self.Log_N + 1):
			if dd & 1:
				v = self.kprev[k][v]
			dd >>= 1
		if u == v:
			return u
		for k in reversed(range(self.Log_N)):
			pu = self.kprev[k][u]
			pv = self.kprev[k][v]
			if pu != pv:
				(u, v) = (pu, pv)
		return self.kprev[0][u]
import sys
input = sys.stdin.buffer.readline
(N, M) = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	graph[a - 1].append(b - 1)
	graph[b - 1].append(a - 1)
Query = [list(map(int, input().split())) for _ in range(M)]
lca = Doubling(graph)
for A in Query:
	N = A[0]
	node = 0
	ok = True
	for a in A[1:]:
		a -= 1
		an = lca.LCAquery(a, node)
		if an != node and lca.Depth[a] - lca.Depth[an] > 1:
			ok = False
			break
		elif a != 0 and lca.Depth[a] > lca.Depth[node]:
			node = lca.prev[a]
	print('YES' if ok else 'NO')


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def gcd(a, b):
	if a == b:
		return a
	while b > 0:
		(a, b) = (b, a % b)
	return a

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24
sys.setrecursionlimit(200005)
timer = 0

def solve():
	(n, m) = sep()
	graph = [[] for _ in range(n)]
	for _ in range(n - 1):
		(a, b) = sep()
		a -= 1
		b -= 1
		graph[a].append(b)
		graph[b].append(a)
	l = n.bit_length()
	up = [[0] * (l + 1) for _ in range(n)]
	tin = [0] * n
	tout = [0] * n

	@iterative
	def dfs(i, p):
		global timer
		timer += 1
		tin[i] = timer
		up[i][0] = p
		for j in range(1, l + 1):
			up[i][j] = up[up[i][j - 1]][j - 1]
		for c in graph[i]:
			if c == p:
				continue
			yield dfs(c, i)
		timer += 1
		tout[i] = timer
		yield

	def is_ancestor(a, b):
		return tin[a] <= tin[b] and tout[a] >= tout[b]

	def lca(u, v):
		if is_ancestor(u, v):
			return u
		if is_ancestor(v, u):
			return v
		for i in range(l, -1, -1):
			if not is_ancestor(up[u][i], v):
				u = up[u][i]
		return up[u][0]
	parent = [0] * n
	distance = [0] * n

	@iterative
	def dfs1(i, p, d):
		distance[i] = d
		parent[i] = p
		for c in graph[i]:
			if c == p:
				continue
			yield dfs1(c, i, d + 1)
		yield
	dfs1(0, 0, 0)
	dfs(0, 0)
	for _ in range(m):
		temp = lis()
		ma = -1
		for i in range(1, len(temp)):
			temp[i] -= 1
			if distance[temp[i]] > ma:
				ma = distance[temp[i]]
				mat = temp[i]
		u = mat
		f = 0
		for i in range(1, len(temp)):
			v = temp[i]
			anc = lca(u, v)
			if anc != v and anc != parent[v]:
				print('NO')
				f = 1
				break
		if f == 0:
			print('YES')
solve()


import sys
from collections import deque
input = sys.stdin.readline
(n, m) = list(map(int, input().split()))
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

class Graph:

	def __init__(self, V):
		self.V = V
		self.adj = [[] for i in range(V)]

	@bootstrap
	def DFSUtil(self, temp, v, visited, depth, parent, Tin, Tout, T):
		visited[v] = True
		Tin[v] = T[0]
		T[0] += 1
		temp.append(v)
		for i in self.adj[v]:
			if visited[i] == False:
				depth[i] = depth[v] + 1
				parent[i] = v
				temp = (yield self.DFSUtil(temp, i, visited, depth, parent, Tin, Tout, T))
		Tout[v] = T[0]
		T[0] += 1
		yield temp

	def addEdge(self, v, w):
		self.adj[v].append(w)
		self.adj[w].append(v)
G = Graph(n)
for _ in range(0, n - 1):
	(u, v) = list(map(int, input().split()))
	u -= 1
	v -= 1
	G.addEdge(u, v)
visited = [False] * n
depth = [0] * n
parent = [0] * n
Tin = [0 for _ in range(n)]
Tout = [0 for _ in range(n)]
T = [0]
G.DFSUtil([], 0, visited, depth, parent, Tin, Tout, T)
for _ in range(0, m):
	v = list(map(int, input().split()))
	v = v[1:]
	max_depth = 0
	max_depth_node = 0
	for i in range(0, len(v)):
		if depth[v[i] - 1] > max_depth:
			max_depth = depth[v[i] - 1]
			max_depth_node = v[i] - 1
	for i in range(0, len(v)):
		v[i] = parent[v[i] - 1]
	ans = 'YES'
	for i in range(0, len(v)):
		if not (Tin[v[i]] <= Tin[max_depth_node] and Tout[max_depth_node] <= Tout[v[i]]):
			ans = 'NO'
			break
	print(ans)


import sys
from collections import Counter

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7

class LCA:

	def __init__(self, nodes, root):
		self.N = len(nodes)
		nv = 1
		MAX = 0
		while nv < N:
			nv *= 2
			MAX += 1
		self.MAX = MAX
		self.nxt = list2d(MAX, N, -1)
		self.depths = self.dfs(N, nodes, root)
		for k in range(1, MAX):
			for v in range(N):
				if self.nxt[k - 1][v] == -1:
					continue
				self.nxt[k][v] = self.nxt[k - 1][self.nxt[k - 1][v]]

	def dfs(self, N, nodes, src):
		stack = [(src, -1, 0)]
		dist = [INF] * N
		while stack:
			(u, prev, c) = stack.pop()
			dist[u] = c
			self.nxt[0][u] = prev
			for v in nodes[u]:
				if v != prev:
					stack.append((v, u, c + 1))
		return dist

	def get_lca(self, a, b):
		if self.depths[a] > self.depths[b]:
			(a, b) = (b, a)
		gap = self.depths[b] - self.depths[a]
		for i in range(self.MAX):
			if gap & 1 << i:
				b = self.nxt[i][b]
		if a == b:
			return a
		else:
			for i in range(self.MAX - 1, -1, -1):
				a2 = self.nxt[i][a]
				b2 = self.nxt[i][b]
				if a2 != b2:
					a = a2
					b = b2
			return self.nxt[0][a]
(N, Q) = MAP()
nodes = [[] for i in range(N)]
for _ in range(N - 1):
	(a, b) = MAP()
	a -= 1
	b -= 1
	nodes[a].append(b)
	nodes[b].append(a)
lca = LCA(nodes, 0)
for _ in range(Q):
	li = [v - 1 for v in LIST()[1:]]
	u = mx = -1
	for v in li:
		if lca.depths[v] > mx:
			mx = lca.depths[v]
			u = v
	mx = -1
	for v in li:
		l = lca.get_lca(u, v)
		dist = lca.depths[v] - lca.depths[l]
		mx = max(mx, dist)
	if mx <= 1:
		YES()
	else:
		NO()


from sys import stdin, stdout
from collections import deque
from math import log
input = stdin.readline
print = stdout.write
(n, m) = map(int, input().split())
e = [[] for _ in range(n + 1)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	e[a].append(b)
	e[b].append(a)
(par, dep) = ([0] * (n + 1), [0] * (n + 1))
q = deque([(1, 1, 1)])
while q:
	(p, d, cur) = q.popleft()
	(par[cur], dep[cur]) = (p, d)
	for u in e[cur]:
		if u == p:
			continue
		q.append((cur, d + 1, u))
nlg = int(log(max(dep), 2)) + 1
dp = [[0] * (n + 1) for _ in range(nlg + 1)]
for i in range(1, n + 1):
	dp[0][i] = par[i]
for i in range(1, nlg + 1):
	for j in range(1, n + 1):
		dp[i][j] = dp[i - 1][dp[i - 1][j]]

def blift(u, jump):
	lg = 0
	while jump:
		if jump % 2:
			u = dp[lg][u]
		jump //= 2
		lg += 1
	return u
for _ in range(m):
	ls = list(map(int, input().split()))
	(sz, ls) = (ls[0], ls[1:])
	path = []
	for u in ls:
		p = par[u]
		path.append((dep[p], p))
	path = list(set(path))
	path.sort()
	ok = 1
	for i in range(1, len(path)):
		if path[i - 1][0] == path[i][0]:
			ok = 0
	if not ok:
		print('NO\n')
		continue
	for i in range(1, len(path)):
		d = path[i][0] - path[i - 1][0]
		if path[i - 1][1] != blift(path[i][1], d):
			ok = 0
	if not ok:
		print('NO\n')
		continue
	print('YES\n')


from collections import defaultdict
import sys, os, io
from sys import stdin
from io import BytesIO, IOBase
BUFSIZE = 8192
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, m) = [int(x) for x in input().split()]
adj = [set() for i in range(n)]
for i in range(n - 1):
	(u, v) = [int(x) for x in input().split()]
	u -= 1
	v -= 1
	adj[u].add(v)
	adj[v].add(u)
tin = defaultdict(lambda : 0)
tout = defaultdict(lambda : 0)
st = [0]
time = 0

@bootstrap
def dfs(node, p):
	global time
	tin[node] = time
	time += 1
	for kid in adj[node]:
		if kid != p:
			level[kid] = level[node] + 1
			yield dfs(kid, node)
			parent[kid] = node
	tout[node] = time
	time += 1
	yield
level = [0] * n
parent = [-1] * n
dfs(0, -1)

def isparent(node, p):
	if tin[p] <= tin[node] and tout[p] >= tout[node]:
		return True
	return False
for _ in range(m):
	k = [int(x) for x in input().split()][1:]
	mxd = 0
	for i in range(len(k)):
		k[i] = parent[k[i] - 1]
		if k[i] == -1:
			k[i] = 0
	mxd = 0
	node = -1
	for i in k:
		if level[i] > mxd:
			mxd = level[i]
			node = i
	f = 0
	for i in k:
		if i != node:
			if isparent(node, i):
				continue
			f = 1
			break
	if f:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
pre = {1: 0}
inm = [0] * (n + 1)
onum = [0] * (n + 1)
edge = [set() for _ in range(n + 1)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	edge[b].add(a)
	edge[a].add(b)
sk = [(1, 1)]
cnt = 0
while sk:
	(ne, se) = sk.pop()
	if se:
		inm[ne] = cnt = cnt + 1
		sk.append((ne, 0))
		for nextne in edge[ne]:
			if nextne not in pre:
				pre[nextne] = ne
				sk.append((nextne, 1))
	else:
		onum[ne] = cnt
for _ in range(m):
	(lt, rt) = (1, n)
	qlst = list(map(int, input().split()))[1:]
	for qry in qlst:
		if qry != 1:
			qry = pre[qry]
		(lt, rt) = (max(lt, inm[qry]), min(rt, onum[qry]))
	print('YES' if lt <= rt else 'NO')


import sys
from collections import defaultdict, namedtuple
readLine = lambda : sys.stdin.readline()
readInt = lambda : int(sys.stdin.readline())
readInts = lambda : [int(x) for x in sys.stdin.readline().split(' ')]
task = namedtuple('Task', ('Vertex', 'Action'))

def dfs(adjList, visited, tin, tout):
	count = 0
	stack = [task(1, 'start')]
	while len(stack) > 0:
		(v, act) = stack.pop()
		if act == 'finish':
			tout[v] = count
			count += 1
		else:
			tin[v] = count
			count += 1
			stack.append(task(v, 'finish'))
			for t in adjList[v]:
				if t not in visited:
					visited.add(t)
					stack.append(task(t, 'start'))
	return count

def main():
	try:
		(n, m) = readInts()
		adjList = defaultdict(list)
		for _ in range(n - 1):
			(a, b) = readInts()
			adjList[a].append(b)
			adjList[b].append(a)
		childToParent = [-1 for x in range(n + 1)]
		childToParent[1] = 1
		depths = [-1 for x in range(n + 1)]
		depths[1] = 0
		visited = [False for x in range(n + 1)]
		visited[1] = True
		q = [1]
		while len(q) > 0:
			cur = q.pop()
			for t in adjList[cur]:
				if not visited[t]:
					childToParent[t] = cur
					depths[t] = depths[cur] + 1
					q.append(t)
					visited[t] = True
		count = 0
		tin = [-1 for x in range(n + 1)]
		tout = [-1 for x in range(n + 1)]
		dfs(adjList, set([1]), tin, tout)
		solns = []
		for _ in range(m):
			query = readInts()[1:]
			parents = {childToParent[q] for q in query}
			currDepths = [(depths[q], q) for q in parents]
			u = max(currDepths, key=lambda x: x[0])[1]
			out = 'YES'
			for v in parents:
				if u == v or (tin[v] <= tin[u] and tout[v] > tout[u]):
					continue
				else:
					out = 'NO'
					break
			solns.append(out)
		print('\n'.join(solns))
	except:
		print(f'Unexpected error: {sys.exc_info()[0].message}')
main()


import os, sys
from io import BytesIO, IOBase

def euler_path(n, path):
	height = [0] * n + [10 ** 10]
	(euler, st, visi, he) = ([], [0], [1] + [0] * (n - 1), 0)
	first = [-1] * n
	while len(st):
		x = st[-1]
		euler.append(x)
		if first[x] == -1:
			first[x] = len(euler) - 1
		while len(path[x]) and visi[path[x][-1]]:
			path[x].pop()
		if not len(path[x]):
			he -= 1
			st.pop()
		else:
			i = path[x].pop()
			he += 1
			st.append(i)
			(height[i], visi[i]) = (he, 1)
	return (height, euler, first)

def cons(euler, height):
	n = len(euler)
	xx = n.bit_length()
	dp = [[n] * n for _ in range(xx)]
	dp[0] = euler
	for i in range(1, xx):
		for j in range(n - (1 << i) + 1):
			(a, b) = (dp[i - 1][j], dp[i - 1][j + (1 << i - 1)])
			dp[i][j] = a if height[a] < height[b] else b
	return dp

def lca(l, r, dp, height, first):
	(l, r) = (first[l], first[r])
	if l > r:
		(l, r) = (r, l)
	xx1 = (r - l + 1).bit_length() - 1
	(a, b) = (dp[xx1][l], dp[xx1][r - (1 << xx1) + 1])
	return a if height[a] < height[b] else b

def main():
	(n, m) = map(int, input().split())
	path = [[] for _ in range(n)]
	for _ in range(n - 1):
		(u1, v1) = map(lambda xx: int(xx) - 1, input().split())
		path[u1].append(v1)
		path[v1].append(u1)
	(height, euler, first) = euler_path(n, path)
	dp = cons(euler, height)
	for _ in range(m):
		ver = list(map(lambda xx: int(xx) - 1, input().split()))[1:]
		ver.sort(key=lambda xx: height[xx])
		for i in range(1, len(ver)):
			(a, b) = (ver[i], ver[i - 1])
			if height[b] - height[lca(a, b, dp, height, first)] > 1:
				print('NO')
				break
		else:
			print('YES')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import os
import sys
from io import BytesIO, IOBase
from math import *
readn = lambda : int(input())
readl = lambda : list(map(int, input().split()))
reads = lambda : input()
readns = lambda : map(int, input().split())

class RangeQuery:

	def __init__(self, data, func=min):
		self.func = func
		self._data = _data = [list(data)]
		(i, n) = (1, len(_data[0]))
		while 2 * i <= n:
			prev = _data[-1]
			_data.append([func(prev[j], prev[j + i]) for j in range(n - 2 * i + 1)])
			i <<= 1

	def query(self, begin, end):
		depth = (end - begin).bit_length() - 1
		return self.func(self._data[depth][begin], self._data[depth][end - (1 << depth)])

class LCA:

	def __init__(self, root, graph):
		self.time = [-1] * len(graph)
		self.path = [-1] * len(graph)
		self.depth = [0] * len(graph)
		P = [-1] * len(graph)
		t = -1
		dfs = [(-1, root)]
		while dfs:
			(prev, node) = dfs.pop()
			self.path[t] = P[node]
			self.time[node] = t = t + 1
			for nei in graph[node]:
				if nei != prev:
					self.depth[nei] = self.depth[node] + 1
					if self.time[nei] == -1:
						P[nei] = node
						dfs.append((node, nei))
		self.rmq = RangeQuery((self.time[node] for node in self.path))

	def __call__(self, a, b):
		if a == b:
			return a
		a = self.time[a]
		b = self.time[b]
		if a > b:
			(a, b) = (b, a)
		return self.path[self.rmq.query(a, b)]

def main():
	(n, m) = readns()
	g = [[] for i in range(n)]
	for i in range(n - 1):
		(u, v) = readns()
		g[u - 1].append(v - 1)
		g[v - 1].append(u - 1)
	lca = LCA(0, g)
	d = lca.depth
	for i in range(m):
		ks = readl()[1:]
		f = True
		try:
			mk = max(ks, key=lambda x: d[x - 1])
			for i in range(len(ks)):
				com = lca(ks[i] - 1, mk - 1)
				if abs(d[com] - d[ks[i] - 1]) > 1:
					f = False
					break
			if f:
				print('YES')
			else:
				print('NO')
		except:
			print('YES')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline
(n, m) = [int(i) for i in input().split()]
tree = [[] for i in range(n + 1)]
for _ in range(n - 1):
	(u, v) = [int(i) for i in input().split()]
	tree[u].append(v)
	tree[v].append(u)
t = 0
tin = [-1 for _ in range(n + 1)]
tout = [-1 for _ in range(n + 1)]
par = [-1 for _ in range(n + 1)]
dep = [-1 for _ in range(n + 1)]
stack = [(1, -1, 0, 1)]
while stack:
	(to, parent, depth, state) = stack.pop()
	if state:
		par[to] = parent
		dep[to] = depth
		tin[to] = t
		t += 1
		stack.append((to, parent, depth, 0))
		for i in tree[to]:
			if i == parent:
				continue
			stack.append((i, to, depth + 1, 1))
	else:
		tout[to] = t
		t += 1
for _ in range(m):
	query = [par[int(i)] if i != '1' else int(i) for i in input().split()]
	del query[0]
	fv = -1
	max_dep = 0
	for i in query:
		if dep[i] > max_dep:
			max_dep = dep[i]
			fv = i
	flg = 0
	for i in query:
		if not (tin[i] <= tin[fv] and tout[fv] <= tout[i]):
			flg = 1
			break
	if flg:
		print('NO')
	else:
		print('YES')