PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#LCA0000057. Các truy vấn trên cây (Tree Queries)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Các truy vấn trên cây (Tree Queries)

Tree Queries

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

An undirected tree is rooted at vertex 11. Each query specifies a set of kk distinct vertices.

Determine whether some path starting at the root and ending at a vertex uu has the following property: every specified vertex is either on that path or exactly one edge away from at least one vertex of the path. Print whether such a path exists.

Input

  • The first line contains n,qn,q.
  • The next n−1n-1 lines contain edges u,vu,v.
  • Each query line starts with kk followed by kk distinct vertex indices.

Output

Print YES or NO for every query, one per line.

Subtasks

General constraints: 2≤n,q≤2⋅1052\le n,q\le2\cdot10^5; 1≤k≤n1\le k\le n; tổng kk trên mọi truy vấn không vượt 2⋅1052\cdot10^5.

  • Subtask 1 (20 points): 1≤n≤401\le n\le 40; 1≤q≤501\le q\le 50.

  • Subtask 2 (30 points): 1≤n≤10001\le n\le 1000; 1≤q≤10001\le q\le 1000.

  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; 1≤q≤2000001\le q\le 200000.

Examples

Input

5 3
1 2
1 3
2 4
3 5
2 4 5
2 2 4
3 4 5 3

Output

NO
YES
NO

Explanation

For (4,5)(4,5), no root-starting path places both vertices on or within one edge of it; the answer is NO. The path 1−2−41-2-4 contains both 2,42,4, so query (2,4)(2,4) is YES. For (4,5,3)(4,5,3), a route through 3,53,5 leaves vertex 44 at least two edges away, giving NO.