codeforces#P1605D. Treelabeling
Treelabeling
Description
Eikooc and Sushi play a game.
The game is played on a tree having nodes numbered to . Recall that a tree having nodes is an undirected, connected graph with edges.
They take turns alternately moving a token on the tree. Eikooc makes the first move, placing the token on any node of her choice. Sushi makes the next move, followed by Eikooc, followed by Sushi, and so on. In each turn after the first, a player must move the token to a node such that
- is adjacent to the node the token is currently on
- has not been visited before
Here denotes the bitwise XOR operation on integers and .
Both the players play optimally. The player who is unable to make a move loses.
The following are examples which demonstrate the rules of the game.
![]() | ![]() |
Before the game begins, Eikooc decides to sneakily relabel the nodes of the tree in her favour. Formally, a relabeling is a permutation of length (sequence of integers wherein each integer from to occurs exactly once) where denotes the new numbering of node .
She wants to maximize the number of nodes she can choose in the first turn which will guarantee her a win. Help Eikooc find any relabeling which will help her do so.
The first line contains a single integer — the number of test cases. The description of each test case is as follows.
The first line of each test case contains an integer — the number of nodes in the tree.
The next lines contain two integers and — denoting an edge between nodes and .
It is guaranteed that the sum of over all test cases does not exceed .
For each test case print any suitable relabeling — a permutation of length which maximizes the number of nodes that can be chosen in the first turn that guarantee a win for Eikooc. If there are multiple such relabelings, you may print any of them.
Input
The first line contains a single integer — the number of test cases. The description of each test case is as follows.
The first line of each test case contains an integer — the number of nodes in the tree.
The next lines contain two integers and — denoting an edge between nodes and .
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case print any suitable relabeling — a permutation of length which maximizes the number of nodes that can be chosen in the first turn that guarantee a win for Eikooc. If there are multiple such relabelings, you may print any of them.
Samples
Note
In the first test case, Eikooc has only one choice. Sushi will have no moves to play after Eikooc chooses this node and Eikooc will win.
In the second test case, . Hence, after Eikooc picks either of the nodes, Sushi will have no moves to play and Eikooc will win. Both and are optimal relabelings.