COCI '25 Contest 5 #4 Slaganje
View as PDFMr. Malnar has ordered a tree with vertices labeled with integers
. Unfortunately, there was a misunderstanding between Mr. Malnar and the sender so Mr. Malnar recieved
copies of the ordered tree.
While waiting for an answer from the sender, Mr. Malnar started placing trees around a regular polygon with vertices also labeled with integers
. More precisely, he placed every vertex of every tree on some vertex of the polygon such that no two vertices belonging to the same tree were placed on the same vertex of the polygon.
Mr. Malnar quickly realized that all diagonals and all sides have been covered by edges. To make sure it was not a coincidence, he tried achieving the same result again from scratch. This turned out to be too difficult for him so Mr. Malnar asks for your help!
Formally, Mr. Malnar is looking for integers
such that for every
the array
is a permutation of integers
and that for every
there exists an integer
such that the edge between vertices
and
is a part of the ordered tree.
It can be proven that such a collection of integers exists for every tree.
Input Specification
The first line contains an integer
, the number of vertices in the tree/polygon.
Each of the following lines contains two integers
and
, labels of vertices connected by an edge in the tree.
Output Specification
Output integers in
rows.
In the -th row output integers
in that order.
Constraints
| Subtask | Points | Constraints |
|---|---|---|
| There exists a vertex u that is a part of every edge. | ||
| The tree is a path graph. | ||
| No additional constraints. |
Sample Input 1
3
1 2
1 3
Sample Output 1
2 3 1
1 2 3
3 1 2
Sample Input 2
4
1 2
1 3
2 4
Sample Output 2
1 4 3 2
3 2 1 4
2 1 4 3
4 3 2 1
Sample Input 3
8
1 2
1 3
2 4
2 5
3 6
4 7
5 8
Sample Output 3
8 1 5 4 3 6 2 7
4 3 6 2 7 8 1 5
2 7 8 1 5 4 3 6
1 5 4 3 6 2 7 8
3 6 2 7 8 1 5 4
7 8 1 5 4 3 6 2
6 2 7 8 1 5 4 3
5 4 3 6 2 7 8 1
Comments