CF1404B.Tree Tag
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of n vertices numbered from 1 to n. Recall that a tree on n vertices is an undirected, connected graph with n−1 edges.
Initially, Alice is located at vertex a, and Bob at vertex b. They take turns alternately, and Alice makes the first move. In a move, Alice can jump to a vertex with distance at most da from the current vertex. And in a move, Bob can jump to a vertex with distance at most db from the current vertex. The distance between two vertices is defined as the number of edges on the unique simple path between them. In particular, either player is allowed to stay at the same vertex in a move. Note that when performing a move, a player only occupies the starting and ending vertices of their move, not the vertices between them.
If after at most 10100 moves, Alice and Bob occupy the same vertex, then Alice is declared the winner. Otherwise, Bob wins.
Determine the winner if both players play optimally.
爱丽丝和鲍勃正在玩一个有趣的“树上捉人”游戏。
该游戏在一个包含 n 个顶点(编号为 1 到 n)的树上进行。回忆一下:一棵含 n 个顶点的树是一个无向、连通图,且恰好包含 n−1 条边。
初始时,爱丽丝位于顶点 a,鲍勃位于顶点 b。他们轮流行动,爱丽丝先行。在一次行动中,爱丽丝可跳跃至距离当前顶点不超过 da 的任意顶点;而鲍勃则可跳跃至距离当前顶点不超过 db 的任意顶点。两个顶点之间的距离定义为它们之间唯一简单路径上的边数。特别地,任一玩家在一次行动中均可选择停留在当前顶点不动。注意:当执行一次移动时,玩家仅占据该次移动的起点与终点顶点,而不占据其间的中间顶点。
若经过至多 10100 次移动后,爱丽丝与鲍勃处于同一顶点,则爱丽丝获胜;否则鲍勃获胜。
假设双方均以最优策略进行游戏,请判断最终获胜者。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). Description of the test cases follows.
The first line of each test case contains five integers n,a,b,da,db (2≤n≤105, 1≤a,b≤n, a=b, 1≤da,db≤n−1) — the number of vertices, Alice's vertex, Bob's vertex, Alice's maximum jumping distance, and Bob's maximum jumping distance, respectively.
The following n−1 lines describe the edges of the tree. The i-th of these lines contains two integers u, v (1≤u,v≤n,u=v), denoting an edge between vertices u and v. It is guaranteed that these edges form a tree structure.
It is guaranteed that the sum of n across all test cases does not exceed 105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含五个整数 n,a,b,da,db(2≤n≤105,1≤a,b≤n,a=b,1≤da,db≤n−1),分别表示顶点数量、Alice 所在的顶点、Bob 所在的顶点、Alice 的最大跳跃距离以及 Bob 的最大跳跃距离。
接下来的 n−1 行描述树的边。其中第 i 行包含两个整数 u、v(1≤u,v≤n,u=v),表示顶点 u 与顶点 v 之间存在一条边。保证这些边构成一棵树。
保证所有测试用例中 n 的总和不超过 105。
输出格式
For each test case, output a single line containing the winner of the game: "Alice" or "Bob".
对于每个测试用例,输出一行,包含游戏的获胜者:“Alice”或“Bob”。
输入输出样例
输入#1
4 4 3 2 1 2 1 2 1 3 1 4 6 6 1 2 5 1 2 6 5 2 3 3 4 4 5 9 3 9 2 5 1 2 1 6 1 9 1 3 9 5 7 9 4 8 4 3 11 8 11 3 3 1 2 11 9 4 9 6 5 2 10 3 2 5 9 8 3 7 4 7 10
输出#1
Alice Bob Alice Alice
说明/提示
In the first test case, Alice can win by moving to vertex 1. Then wherever Bob moves next, Alice will be able to move to the same vertex on the next move.

In the second test case, Bob has the following strategy to win. Wherever Alice moves, Bob will always move to whichever of the two vertices 1 or 6 is farthest from Alice.

在第一个测试用例中,Alice 可以通过移动到顶点 1 获胜。此后,无论 Bob 下一步移动到哪个顶点,Alice 都能在接下来的回合中移动到该同一顶点。

在第二个测试用例中,Bob 采用如下获胜策略:无论 Alice 移动到何处,Bob 总是移动到两个顶点 1 和 6 中距离 Alice 更远的那个顶点。

输入解题思路,AI测评打分。不知道怎么写?