Valentine's Day '19 S5 - A Top Tree Problem

View as PDF

Submit solution


Points: 25 (partial)
Time limit: 2.5s
Java 3.0s
Memory limit: 512M

Author:
Problem types

Jonathan is making a connected tree of N nodes, and N1 bidirectional edges. He wants to give the tree to <REDACTED> for Valentine's Day. However, he wants to make sure the tree is good looking.

Jonathan defines a simple path in the tree as a path where every node is traversed at most once.

To determine whether the tree is good looking, he will give you Q queries that you must answer for him:

  • v k u_1 u_2 ... u_k Is there a simple path that visits u1,u2,,uk in that order, if at most v bidirectional edges are added into the tree?

3kmin(N,20), 0v2. ui is guaranteed to be distinct.

Input Specification

The first line will contain two integers, N,Q (3N105,1Q2×104).

The next N1 lines will each contain two integers a,b (1a,bN), indicating that there is a bidirectional edge between a and b. It is guaranteed that the tree is connected.

The next Q lines will each contain a query as defined above.

Output Specification

For each query, output 1 if the answer to the query is yes, and 0 otherwise.

Constraints

Subtask 1 [5%]

N,Q100

v=0

Subtask 2 [25%]

v=0

Subtask 3 [70%]

No additional constraints.

Sample Input 1

Copy
5 3
1 2
2 3
2 4
1 5
0 3 5 2 3
0 3 3 4 5
0 3 1 3 2

Sample Output 1

Copy
1
0
0

Sample Input 2

Copy
7 5
1 2
2 3
2 4
4 5
5 6
5 7
0 3 3 4 7
0 4 2 5 7 6
1 4 2 5 7 6
2 5 3 4 2 1 7
1 6 6 5 7 4 1 3

Sample Output 2

Copy
1
0
1
1
0

Comments

There are no comments at the moment.