QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#11316. 树上博弈

Statistics

Mr. Panda 和 Mr. Sheep 在一个具有 $N$ 个顶点和 $N$ 条边的连通无向图上玩游戏。最初,Mr. Panda 和 Mr. Sheep 站在图上两个不同的顶点 $A$ 和 $B$ 上。游戏轮流进行,Mr. Panda 先手。每一回合,玩家可以选择留在原地或移动到相邻的顶点。Mr. Panda 只能移动到未被 Mr. Sheep 访问过的顶点。

有些顶点被标记为目的地。当 Mr. Panda 到达任何一个目的地顶点时,游戏结束,Mr. Panda 获胜。

请帮助 Mr. Panda 判断在双方都采取最优策略的情况下,他是否能赢得游戏。

输入格式

第一行包含一个整数 $T$ ($1 \le T \le 20$),表示测试用例的数量。接下来是 $T$ 个测试用例。

每个测试用例包含一个整数 $N$ ($1 \le N \le 2 \times 10^5$),表示图的顶点数和边数。

接下来的 $N$ 行,每行包含两个整数 $x$ 和 $y$ ($1 \le x \neq y \le N$),表示顶点 $x$ 和顶点 $y$ 之间有一条边。

接下来的一行包含一个整数 $M$ ($1 \le M \le N$),表示目的地的数量,随后的一行包含 $M$ 个不同的整数:$v_1, v_2, \dots, v_M$ ($1 \le v_i \le N$)。

最后一行包含两个整数 $A$ 和 $B$ ($1 \le A \neq B \le N$),其中 $A$ 是 Mr. Panda 的起始顶点,$B$ 是 Mr. Sheep 的起始顶点。

输出格式

对于每个测试用例,首先输出 “Case x:”,其中 x 是测试用例编号(从 1 开始)。如果 Mr. Panda 能赢得游戏,输出 “Panda”;否则(平局或失败)输出 “Sheep”。

样例

输入 1

2
5
1 2
2 3
3 4
4 5
5 2
1
3
1 5
5
1 2
2 3
3 4
4 5
5 3
1
3
1 5

输出 1

Case 1: Panda
Case 2: Sheep

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.