CF1605D.Treelabeling

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Eikooc and Sushi play a game.

The game is played on a tree having nn nodes numbered 11 to nn . Recall that a tree having nn nodes is an undirected, connected graph with n1n-1 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 uu such that

  • uu is adjacent to the node vv the token is currently on
  • uu has not been visited before
  • uvmin(u,v)u \oplus v \leq min(u, v)

Here xyx \oplus y denotes the bitwise XOR operation on integers xx and yy .

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.

Suppose Eikooc starts the game by placing the token at node 44 . Sushi then moves the token to node 66 , which is unvisited and adjacent to 44 . It also holds that 64=2min(6,4)6 \oplus 4 = 2 \leq min(6, 4) . In the next turn, Eikooc moves the token to node 55 , which is unvisited and adjacent to 66 . It holds that 56=3min(5,6)5 \oplus 6 = 3 \leq min(5, 6) . Sushi has no more moves to play, so she loses. Suppose Eikooc starts the game by placing the token at node 33 . Sushi moves the token to node 22 , which is unvisited and adjacent to 33 . It also holds that 32=1min(3,2)3 \oplus 2 = 1 \leq min(3, 2) . Eikooc cannot move the token to node 66 since 62=4min(6,2)6 \oplus 2 = 4 \nleq min(6, 2) . Since Eikooc has no moves to play, she loses.Before the game begins, Eikooc decides to sneakily relabel the nodes of the tree in her favour. Formally, a relabeling is a permutation pp of length nn (sequence of nn integers wherein each integer from 11 to nn occurs exactly once) where pip_i denotes the new numbering of node ii .

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 t (1t105)t~(1 \le t \le 10^5) — the number of test cases. The description of each test case is as follows.

The first line of each test case contains an integer n (1n2105)n~(1 \le n \le 2 \cdot 10^5) — the number of nodes in the tree.

The next n1n-1 lines contain two integers uu and vv (1u,vn;uv)(1 \le u, v \le n; u \neq v) — denoting an edge between nodes uu and vv .

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5 .

输出格式

For each test case print any suitable relabeling — a permutation of length nn 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.

输入输出样例

  • 输入#1

    3
    1
    2
    1 2
    3
    1 2
    1 3

    输出#1

    1
    2 1
    1 2 3

说明/提示

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, 12=3min(1,2)1 \oplus 2 = 3 \nleq min(1, 2) . Hence, after Eikooc picks either of the nodes, Sushi will have no moves to play and Eikooc will win. Both {1,2}\{1, 2\} and {2,1}\{2, 1\} are optimal relabelings.

首页