#P5801. [SEERC 2019] Game on a Tree
[SEERC 2019] Game on a Tree
Description
Alice and Bob play a game on a tree. At the beginning, all nodes on the tree are white.
Alice moves first. She may choose any node and place a token on it, and that node becomes black. After that, the players take turns. In each turn, the current player may move the token from its current node to a white ancestor of that node or to a white child of that node, and the node moved to becomes black. The player who cannot make a move loses.
In a rooted tree, an ancestor of a node is any node on the path from the root to node .
In a rooted tree, a child of a node is a node such that is on the path from the root to and is the parent of .
The root of the tree is node .
Input Format
The first line contains an integer , the number of nodes in the tree.
Each of the next lines contains two integers and , denoting an edge of the tree. The testdata guarantees that these edges form a tree.
Output Format
Output one line. If Alice wins the game, output Alice; otherwise, output Bob.
4
1 2
2 3
3 4
Bob
7
2 1
2 6
1 3
2 5
7 2
2 4
Alice
Hint
In the first sample, the tree is a chain of nodes, so Bob can always move the token to the last remaining white node.
In the second sample, Alice’s best strategy is to place the token on node first, and then node becomes black. Bob can only move the token to node . Alice can choose node or to move to. Bob can then only choose node . After Alice chooses any white child of node , Bob will have no move.
Translated by ChatGPT 5
京公网安备 11011102002149号