QOJ.ac

QOJ

実行時間制限: 5.0 s メモリ制限: 256 MB 満点: 100 ハック可能 ✓

#11220. 树上博弈

統計

Mr. Panda 和 Mr. Sheep 在一棵有 $n$ 个顶点的树上玩游戏。初始时,一个棋子位于顶点 $1$。Mr. Panda 和 Mr. Sheep 轮流移动棋子,由 Mr. Panda 先手。

在每一回合中,玩家必须将棋子移动到另一个顶点。游戏有一个限制:除了第一步之外,当前移动的距离必须严格大于对手在上一个回合中移动的距离。如果当前回合没有合法的移动方式,则该玩家输掉游戏。

Mr. Sheep 觉得这个游戏对他不公平。因此,Mr. Panda 允许 Mr. Sheep 选择树的一个连通子图,该子图必须包含顶点 $1$ 以及当前棋子所在的顶点。如果 Mr. Panda 和 Mr. Sheep 都采取最优策略,Mr. Sheep 有多少种不同的方式选择子图,使得他能够获胜?如果两种方式选择的子图不同,则视为不同的方式。由于答案可能非常大,你只需要输出其对 $(10^9 + 7)$ 取模的结果。

输入格式

第一行包含一个整数 $T$ ($1 \le T \le 10$),表示测试用例的数量。接下来是 $T$ 个测试用例。 对于每个测试用例,第一行包含一个整数 $n$ ($1 \le n \le 2 \times 10^5$),表示树的顶点数。 接下来的 $n-1$ 行,每行包含两个整数 $x$ 和 $y$ ($1 \le x, y \le n$),表示顶点 $x$ 和顶点 $y$ 之间有一条边。保证给定的边构成一棵树。

输出格式

对于每个测试用例,输出一行 “Case #x: y”,其中 $x$ 是测试用例编号(从 $1$ 开始),$y$ 是获胜方式的数量对 $(10^9 + 7)$ 取模的结果。

样例

样例输入 1

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

样例输出 1

Case #1: 1
Case #2: 5

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.