#P6665. [清华集训 2016] Alice 和 Bob 又在玩游戏

[清华集训 2016] Alice 和 Bob 又在玩游戏

Description

Alice and Bob are playing a game.

There are nn nodes and mm edges (0mn1)(0\le m\le n-1), 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 xx and deletes xx 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 1321-3-2, node 11 is the root. After deleting node 11, node 33 is still the parent of node 22.

Determine whether the first player has a winning strategy.

Input Format

This problem has multiple test cases.

The first line contains a positive integer TT, meaning there are TT test cases in this test point; then follow TT test cases.

For each test case:

The first line contains two integers n,mn, m, representing the number of nodes and edges (nodes are numbered starting from 11).

The next mm lines each contain two positive integers a,ba, b, indicating there is an edge between node aa and node $b. There are no multiple edges in the input.

Output Format

Output TT 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 11 on the first move.

Constraints

For 100%100\% of the data, 1T101≤T≤10, 1n1051≤n≤10^5, n2×105∑n≤2×10^5, 0mn10≤m≤n−1. The input guarantees there is no cycle, and the size of each tree is 5×104≤5×10^4.

Translated by ChatGPT 5