atcoder#HITACHI2020C. ThREE
ThREE
Score : points
Problem Statement
We have a tree with vertices. The vertices are numbered to , and the -th edge connects Vertex and Vertex .
Takahashi loves the number . He is seeking a permutation of integers from to satisfying the following condition:
- For every pair of vertices , if the distance between Vertex and Vertex is , the sum or product of and is a multiple of .
Here the distance between Vertex and Vertex is the number of edges contained in the shortest path from Vertex to Vertex .
Help Takahashi by finding a permutation that satisfies the condition.
Constraints
- The given graph is a tree.
Input
Input is given from Standard Input in the following format:
Output
If no permutation satisfies the condition, print -1
.
Otherwise, print a permutation satisfying the condition, with space in between. If there are multiple solutions, you can print any of them.
5
1 2
1 3
3 4
3 5
1 2 5 4 3
The distance between two vertices is for the two pairs and .
Thus, this permutation satisfies the condition.