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