CF1328E Tree Queries
Description
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 Format
N/A
Output Format
N/A
Explanation/Hint
The picture corresponding to the example:

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 $ .