CF1702G1.Passable Paths (easy version)
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is an easy version of the problem. The only difference between an easy and a hard version is in the number of queries.
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 n−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, 1,5,4, 1,4 are passable, and 1,3,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.
这是一个该问题的简单版本。简单版本与困难版本的唯一区别在于查询次数。
Polycarp 构造了一棵包含 n 个顶点的树。我们提醒您:一棵包含 n 个顶点的树,是指一个具有 n 个顶点和 n−1 条边、无环且连通的无向图。
他将一个顶点集合称为可通行的(passable),如果树中存在一条路径,该路径经过该集合中的每个顶点,且不重复经过任何一条边(但可以经过其他顶点,即不属于该集合的顶点)。
换言之,若存在一条简单路径,其经过该集合的所有顶点(也可能经过其他顶点),则称该顶点集合为可通行的。
例如,对于下图所示的树,集合 {3,2,5}、{1,5,4}、{1,4} 是可通行的,而 {1,3,5}、{1,2,3,4,5} 则不是。

Polycarp 要求你回答 q 个查询。每个查询给出一个顶点集合。对每个查询,你需要判断对应的顶点集合是否可通行。
输入格式
The first line of input contains a single integer n (1≤n≤2⋅105) — number of vertices.
Following n−1 lines a description of the tree..
Each line contains two integers u and v (1≤u,v≤n, u=v) — indices of vertices connected by an edge.
Following line contains single integer q (1≤q≤5) — number of queries.
The following 2⋅q lines contain descriptions of sets.
The first line of the description contains an integer k (1≤k≤n) — the size of the set.
The second line of the description contains k of distinct integers p1,p2,…,pk (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⋅105.
输入的第一行包含一个整数 n(1≤n≤2⋅105)——顶点的数量。
接下来的 n−1 行描述一棵树。
每行包含两个整数 u 和 v(1≤u,v≤n,u=v)——由一条边连接的两个顶点的下标。
接下来一行包含一个整数 q(1≤q≤5)——查询的数量。
随后的 2⋅q 行包含各集合的描述。
每个集合描述的第一行是一个整数 k(1≤k≤n)——该集合的大小。
每个集合描述的第二行包含 k 个互不相同的整数 p1,p2,…,pk(1≤pi≤n)——该集合中各顶点的下标。
保证所有查询中 k 值的总和不超过 2⋅105。
输出格式
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).
输出 q 行,每行包含对应查询的答案。若该集合是可通行的,则输出 "YES";否则输出 "NO"。
答案大小写不敏感(例如,字符串 "yEs"、"yes"、"Yes" 和 "YES" 均被视为肯定回答)。
输入输出样例
输入#1
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
输出#1
YES NO YES NO YES
输入#2
5 1 2 3 2 2 4 5 2 4 2 3 1 3 3 4 5 3 2 3 5 1 1
输出#2
YES NO YES YES
输入解题思路,AI测评打分。不知道怎么写?