Loading

2019-2020 ICPC Asia Hong Kong Regional Contest B. Binary Tree(思维)

In computer science, a binary tree is a rooted tree in which each node has at most two children. In this problem, let's denote 𝑛n as the number of nodes, 𝑙l as the number of leaf nodes and ℎh as the height of the tree (a tree consisting of only a root node has a height of 00).

Alice and Bob are playing a game with a binary tree. In this game, Alice and Bob have a binary tree, in which node 11 is the root. They take turns to perform operations on the tree, and Alice always takes the first turn. In each operation, the player taking the turn must choose a node 𝑝p (any node including the root can be chosen), and remove the subtree rooted at 𝑝p from the tree. Obviously, the remaining graph, if not empty, is still a binary tree. Then they continue to play with the resulting tree. To make the game more interesting, there is a restriction on which nodes can be chosen as 𝑝p: the subtree rooted at 𝑝p (the subtree to be removed) must be a perfect full binary tree. Note that a perfect full binary tree is a binary tree in which all interior (non-leaf) nodes have two children and all leaf nodes have the same depth. It can be easily shown that in a perfect full binary tree, the equation 𝑙=2ℎl=2h holds, so does the equation 𝑛=2ℎ+1−1n=2h+1−1. In particular, a tree consisting of only a root node is also a perfect full binary tree. When a player is unable to perform a legal operation, the game ends and that player loses, which means the other player wins.

imgThree examples of perfect full binary trees.

Alice and Bob are both very smart and always play optimally. Can you determine who would win the game?

Input

The input contains multiple cases. The first line of the input contains a single positive integer 𝑇T, the number of cases.

For each case, the first line of the input contains a single integer 𝑛n (1≤𝑛≤50001≤n≤5000), the number of nodes in the binary tree. The following 𝑛−1n−1 lines each contains two integers 𝑥,𝑦x,y (1≤𝑥≤𝑛,1≤𝑦≤𝑛1≤x≤n,1≤y≤n), which denotes an edge between node 𝑥x and 𝑦y. It is guaranteed that the input graph is a binary tree rooted at node 11.

It's guaranteed that the sum of 𝑛n over all cases does not exceed 5000050000.

Output

For each case, print the string "Alice" in a single line if Alice would win the game, otherwise print the string "Bob".

Example

input

Copy

1
5
1 2
1 3
3 4
3 5

output

Copy

Alice

给一棵二叉树,两人轮流每次拿走一棵满二叉树(子树),其中一个节点也算子树,而且拿完后剩下的必须仍为一棵二叉树,问先手必胜还是必败。

注意到一棵满二叉树必须为奇数个点,这和拿走一个点的效果实际上是一样的,因此只需要看

这棵树有多少个点就行,n为奇数先手必胜。

(一开始sb了,想成了统计有多少个互不包含的满二叉树以及剩下的点的个数,理论上也能过但一直wa。。)

posted @ 2020-12-15 16:16  脂环  阅读(91)  评论(0编辑  收藏  举报