QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100

#2376. 树上博弈

Statistics

Alice 和 Bob 在一棵树上玩游戏。初始时,所有节点都是白色的。

Alice 先手。她选择任意一个节点并放上一枚棋子,该节点变为黑色。之后,玩家轮流移动棋子。在每一回合中,玩家将棋子从当前位置移动到一个祖先节点或后代节点,前提是该节点不是黑色的。移动到的节点也会变为黑色。无法移动棋子的玩家输掉游戏。

谁会赢得这场游戏?

在有根树中,节点 $v$ 的祖先是指路径上位于 $v$ 和根节点之间的任意节点。 在有根树中,节点 $v$ 的后代是指任意节点 $w$,使得节点 $v$ 位于路径上 $w$ 和根节点之间。

我们认为树的根节点是 1。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 100\,000$),表示节点的数量。 接下来的 $n - 1$ 行,每行包含两个整数 $u$ 和 $v$ ($1 \le u, v \le n$),表示树的边。保证这些边构成一棵树。

输出格式

如果 Alice 获胜,输出一行 “Alice”(不含引号)。否则,输出 “Bob”。

样例

样例输入 1

4
1 2
2 3
3 4

样例输出 1

Bob

样例输入 2

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

样例输出 2

Alice

说明

在第一个测试用例中,树是一条直线且有 4 个节点,因此 Bob 总能选择最后一个白色节点。

在第二个测试用例中,Alice 的最优策略是将棋子放在 3 号节点。该节点将变为黑色。Bob 必须选择 1 号节点。Alice 可以选择 4、5、6 或 7 号节点中的任意一个。Bob 只能选择 2 号节点。Alice 选择 2 号节点的任意一个白色子节点,Bob 将无法进行移动。

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.