#P10212. [CTS2024] 众生之门
[CTS2024] 众生之门
Background
Problem Description
Given , an undirected tree with nodes, and two different nodes on the tree. Each edge has length . Nodes are labeled with integers from to . Let denote the distance between and (i.e., the number of edges on the simple path). You need to output a permutation of to that satisfies the following two conditions:
- , .
- Let . Under the above conditions, your permutation should minimize , where denotes bitwise XOR.
If there are multiple valid permutations, you may output any one of them.
Input Format
Read input from standard input.
This problem contains multiple test cases. The first line contains a positive integer , the number of test cases.
For each test case, the first line contains three positive integers . The next lines each contain two positive integers , indicating that there is a direct undirected road between and (i.e., an edge of the tree).
Output Format
Write output to standard output.
For each test case, output one line of positive integers . You must ensure it is a permutation of to with and , and that is minimized.
3
3 1 3
1 2
2 3
4 3 4
1 2
2 3
2 4
5 1 2
1 2
1 3
2 4
3 5
1 2 3
3 2 1 4
1 5 3 4 2
见题目目录下的 2.in 与 2.ans。
Hint
Sample 1 Explanation
This sample contains three test cases.
- For the first test case, the minimum possible value of is . The sample output is , where .
- For the second test case, the minimum possible value of is . The sample output is , where and ; another valid output is .
- For the third test case, the minimum possible value of is . The sample output is , where , , , .
Sample 2 Explanation
Note that this input consists of all tree shapes that satisfy and all possible relative positions of different and .
This sample is undoubtedly a selfless gift from the kind problem setter. I forgot what happened in the middle. The problem setter believes that this wonderful sample can provide strong help to you on your dream-chasing road of getting AC on this problem.
Constraints
Let denote the sum of over all test cases in a single test file. For all testdata,
- .
- , .
- , .
- , .
- The input pairs form a tree.
| Subtask ID | Special Property | Score | ||
|---|---|---|---|---|
| 1 | None | 5 | ||
| 2 | 8 | |||
| 3 | A | 17 | ||
| 4 | B | 20 | ||
| 5 | C | 17 | ||
| 6 | D | 10 | ||
| 7 | None | 23 |
Special Property A: It is guaranteed that the degree of each node is at most .
Special Property B: It is guaranteed that for any , $\mathrm{dist}(s,x)+\mathrm{dist}(x,t)\le \mathrm{dist}(s,t)+2$.
Special Property C: It is guaranteed that .
Special Property D: This subtask has five test points. For each test point, it is guaranteed that and . In each test case, is generated uniformly at random from , is generated uniformly at random from excluding , and the tree is generated uniformly at random from all labeled trees on nodes.
Translated by ChatGPT 5