GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Sunday 10 July 2022

[Solution] Passable Paths (easy version) Codeforces Solution


G1. Passable Paths (easy version)
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 n1 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).

Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

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.

Input

The first line of input contains a single integer n (1n2105) — 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 n1 lines a description of the tree..

Each line contains two integers u and v (1u,vnuv) — indices of vertices connected by an edge.

Following line contains single integer q (1q5) — number of queries.

The following 2q lines contain descriptions of sets.

The first line of the description contains an integer k (1kn) — the size of the set.

The second line of the description contains k of distinct integers p1,p2,,pk (1pin) — indices of the vertices of the set.

It is guaranteed that the sum of k values for all queries does not exceed 2105.

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

No comments:

Post a Comment