atcoder#ARC117D. [ARC117D] Miracle Tree
[ARC117D] Miracle Tree
Score : points
Problem Statement
We have a tree with vertices, numbered . The -th edge connects Vertex and Vertex .
A boy E869120 found this tree and wants to write an integer in each vertex to surprise another boy square1001. For that, the following conditions need to be satisfied, where is the integer written on Vertex .
Condition 1: holds. Condition 2: holds for every pair . Condition 3: the value should be minimized while satisfying Conditions 1 and 2.
Here, is:
- the length of the simple path (the path without repetition of the same vertex) from Vertex to .
- In other words, it is the value where the simple path is ().
Construct one way to write integers that surprises square1001.
Constraints
- The given graph is a tree.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print a line containing integers to write on the vertices, in this order, with space as separator.
If there are multiple ways to write integers that satisfy the conditions in the Problem Statement, any of them will be accepted.
2
1 2
2 1
If we write an integer on Vertex and an integer on Vertex , we have and , satisfying Condition 2.
The other conditions are also satisfied, so we can surprise square1001 this way.
will also be accepted.
4
1 2
1 4
2 3
3 2 1 4
will also be accepted.