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

#LCA0000063. Những đường đi có thể đi qua — bản khó (Passable Paths (hard version))

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Những đường đi có thể đi qua — bản khó (Passable Paths (hard version))

Passable Paths (hard version)

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

An undirected tree has nn vertices labeled 11 through nn. Each query selects kk distinct vertices. Decide whether there exists one simple path in the tree containing every selected vertex. Its endpoints may be any vertices in the tree, not necessarily vertices from the query set.

Input

First line: nn, followed by n−1n-1 edges u vu\ v. Next line: qq. Each query consists of kk followed by kk selected vertices.

Output

For every query output YES if the path exists, or NO otherwise. Answers are accepted case-insensitively.

Subtasks

General constraints: 1≤n≤2⋅1051\le n\le 2\cdot10^5; 1≤q≤1051\le q\le 10^5; tổng số đỉnh được liệt kê trong các truy vấn không vượt 2⋅1052\cdot10^5. Trong mỗi truy vấn: 1≤k≤n1\le k\le n, các đỉnh phân biệt.

  • 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≤1000001\le q\le 100000.

Examples

Input

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

Output

YES
NO
YES
NO
YES

Explanation

Vertices 3,2,53,2,5 lie on the path 3→2→4→53\to2\to4\to5. All five vertices cannot fit on a single simple path because of branching at vertex 22.