Passable Paths (hard version) solution codeforces

Passable Paths (hard version) solution codeforces β€“ Polycarp grew a tree from π‘›n vertices. We remind you that a tree of π‘›n vertices is an undirected connected graph of π‘›n vertices and π‘›βˆ’1nβˆ’1 edges that does not contain cycles.

He calls a set of vertices passable if there is such a path in the tree that passes through each vertex of this set without passing through any edge twice. The path can visit other vertices (not from this set).

In other words, a set of vertices is called passable if there is a simple path that passes through all the vertices of this set (and possibly some other).

For example, for a tree below sets {3,2,5}{3,2,5}, {1,5,4}{1,5,4}, {1,4}{1,4} are passable, and {1,3,5}{1,3,5}, {1,2,3,4,5}{1,2,3,4,5} are not.

Polycarp asks you to answer π‘žq queries. Each query is a set of vertices. For each query, you need to determine whether the corresponding set of vertices is passable.

Input

The first line of input contains a single integer π‘›n (1≀𝑛≀2β‹…1051≀n≀2β‹…105) β€” number of vertices.

Following π‘›βˆ’1nβˆ’1 lines a description of the tree..

Each line contains two integers π‘’u and π‘£v (1≀𝑒,𝑣≀𝑛1≀u,v≀n, π‘’≠𝑣uβ‰ v) β€” indices of vertices connected by an edge.

Following line contains single integer π‘žq (1β‰€π‘žβ‰€1051≀q≀105) β€” number of queries.

The following 2β‹…π‘ž2β‹…q lines contain descriptions of sets.

The first line of the description contains an integer π‘˜k (1β‰€π‘˜β‰€π‘›1≀k≀n) β€” the size of the set.

The second line of the description contains π‘˜k of distinct integers π‘1,𝑝2,…,π‘π‘˜p1,p2,…,pk (1≀𝑝𝑖≀𝑛1≀pi≀n) β€” indices of the vertices of the set.

It is guaranteed that the sum of π‘˜k values for all queries does not exceed 2β‹…1052β‹…105.

Output

Output π‘žq lines, each of which contains the answer to the corresponding query. As an answer, output β€œYES” if the set is passable, and β€œNO” otherwise.

You can output the answer in any case (for example, the strings β€œyEsβ€œ, β€œyesβ€œ, β€œYes” and β€œYES” will be recognized as a positive answer).

Examples

input

Copy

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

Copy

YES
NO
YES
NO
YES

input

Copy

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

output

Copy

YES
NO
YES
YES

Leave a Comment