#P8578. [CoE R5] So What Do We Do Now?
[CoE R5] So What Do We Do Now?
Background

Statement: The image above is taken from the Internet, pid:6544352. If there is any infringement, please inform us and it will be deleted.
Problem Description
Given a rooted tree with nodes, where the root is node . Let the subtree rooted at be . You need to assign each node a positive integer weight such that all node weights are exactly , each used once.
Define
where is the range of weights in the subtree rooted at , i.e.
$$R_i=\max_{j \in T_i}\{v_j\}-\min_{j \in T_i}\{v_j\}.$$Among all valid assignments, find one assignment of node weights that minimizes .
Input Format
The first line contains a positive integer , the number of nodes in the tree.
The next lines each contain two positive integers , indicating that there is an edge between and .
Output Format
Output one permutation of , representing the node weights of nodes . Since there may be many valid assignments, you only need to output any one of them.
3
1 2
1 3
1 2 3
2
1 2
1 2
5
1 2
2 3
3 4
4 5
1 2 3 4 5
Hint
Sample Explanation
Input

. It can be proven that there is no construction that makes smaller.
Constraints
For of the testdata, .
For another of the testdata, the tree is a chain.
For another of the testdata, there is one node connected to the other nodes.
For another of the testdata, the tree is a complete binary tree, meaning every non-leaf node has exactly two children.
For of the testdata, .
Translated by ChatGPT 5