[Solution] Passable Paths (easy version) Codeforces Solution
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 vertices. We remind you that a tree of vertices is an undirected connected graph of vertices and 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 , , are passable, and , are not.
Polycarp asks you to answer queries. Each query is a set of vertices. For each query, you need to determine whether the corresponding set of vertices is passable.
The first line of input contains a single integer () — number of vertices.
Round Down the Price Codeforces Solution
Polycarp Writes a String from Memory Codeforces Solution
Train and Queries Codeforces Solution
Not a Cheap String Codeforces Solution
Split Into Two Sets Codeforces Solution
Equate Multisets Codeforces Solution
Passable Paths (easy version) Codeforces Solution
Passable Paths (hard version) Codeforces Solution
Following lines a description of the tree..
Each line contains two integers and (, ) — indices of vertices connected by an edge.
Following line contains single integer () — number of queries.
The following lines contain descriptions of sets.
The first line of the description contains an integer () — the size of the set.
The second line of the description contains of distinct integers () — indices of the vertices of the set.
It is guaranteed that the sum of values for all queries does not exceed .
Output 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).
No comments:
Post a Comment