#P6665. [清华集训 2016] Alice 和 Bob 又在玩游戏
[清华集训 2016] Alice 和 Bob 又在玩游戏
Description
Alice and Bob are playing a game.
There are nodes and edges , forming several rooted trees. For each tree, the root is the node with the smallest index in that connected component. Alice and Bob take turns to move. In each round, a player chooses an undeleted node and deletes and all of its ancestors. The player who cannot make a move loses.
Note: The shape of the trees is fixed at the beginning. Deleting nodes does not change the parent-child relationships among the remaining nodes. For example, for a chain like , node is the root. After deleting node , node is still the parent of node .
Determine whether the first player has a winning strategy.
Input Format
This problem has multiple test cases.
The first line contains a positive integer , meaning there are test cases in this test point; then follow test cases.
For each test case:
The first line contains two integers , representing the number of nodes and edges (nodes are numbered starting from ).
The next lines each contain two positive integers , indicating there is an edge between node and node $b. There are no multiple edges in the input.
Output Format
Output lines. For each line, output who wins when Alice moves first and both Alice and Bob play optimally.
4
2 1
1 2
3 2
1 2
1 3
2 0
3 1
1 2
Alice
Alice
Bob
Alice
Hint
Sample Explanation
In the first test case, the input is a chain, and Alice can delete all nodes in one move.
In the second test case, Alice can win by deleting node on the first move.
Constraints
For of the data, , , , . The input guarantees there is no cycle, and the size of each tree is .
Translated by ChatGPT 5
京公网安备 11011102002149号