QOJ.ac

QOJ

Limite de temps : 2.0 s Limite de mémoire : 1024 MB Points totaux : 100 Difficulté: [afficher] Hackable ✓

#8551. DFS 序 5

Statistiques

Little Cyan Fish 有一棵包含 $n$ 个顶点的树。每个顶点都被标记为 $1$ 到 $n$。现在他想从顶点 $1$ 开始进行深度优先搜索。DFS 序是深度优先搜索过程中访问节点的顺序。如果一个顶点在 DFS 序中处于第 $j$ 个位置($1 \le j \le n$),意味着它是在访问了其他 $j-1$ 个顶点之后被访问的。由于节点的子节点可以以任意顺序遍历,因此存在多种可能的 DFS 序。以下伪代码描述了生成 DFS 序的方法。函数 generate(x) 返回从顶点 $x$ 开始的 DFS 序:

Algorithm 1 An implementation of depth-first search
1: procedure dfs(vertex x)
2: Append x to the end of dfs_order
3: for each son y of x do  Sons can be iterated in arbitrary order.
4: dfs(y)  The order might be different in each iteration.
5: end for
6: end procedure
7: procedure generate(x)
8: Root the tree at vertex x
9: Let dfs_order be a global variable
10: dfs_order ← empty list
11: dfs(x)
12: return dfs_order
13: end procedure

Little Cyan Fish 在整棵树上进行了 $Q$ 次深度优先搜索,每次都获得了一个 DFS 序。不幸的是,Little Cyan Fish 的内存有限,他只记得每个 DFS 序的一个片段。更不幸的是,Little Cyan Fish 无法确定他的记忆是否正确。对于每个片段,他只记得 $k$ 个数字 $a_1, a_2, \dots, a_k$。他想寻求你的帮助:是否存在一个 DFS 序,使得 $a_1, a_2, \dots, a_k$ 是该 DFS 序的一个连续子段?

输入格式

第一行包含两个整数 $n$ 和 $Q$ ($1 \le n, Q \le 10^5$)。

接下来的 $(n - 1)$ 行,第 $i$ 行包含两个整数 $u_i$ 和 $v_i$ ($1 \le u_i, v_i \le n$),表示树中连接顶点 $u_i$ 和 $v_i$ 的一条边。

接下来的 $Q$ 行描述了所有查询。第 $i$ 行首先包含一个整数 $k_i$ ($k_i \ge 1$),然后是 $k_i$ 个整数 $a_1, a_2, \dots, a_{k_i}$ ($1 \le a_i \le n$),表示一个查询。

保证所有查询的 $k_i$ 之和不超过 $10^6$。

输出格式

对于每个查询,输出一行 “Yes” 或 “No”,表示答案。

样例

输入 1

6 7
1 2
1 3
2 4
3 5
2 6
2 4 1
2 4 2
2 4 3
2 4 4
2 4 5
2 4 6
6 1 2 6 4 3 5

输出 1

No
No
Yes
No
No
Yes
Yes

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.