#P15568. [COCI 2025/2026 #5] 摆放 / Slaganje
[COCI 2025/2026 #5] 摆放 / Slaganje
Background
The full score for this problem is .
Problem Description
Mr. Malnar ordered a tree with vertices, labeled . Unfortunately, due to a communication mistake, he received a total of such trees.
While waiting for a reply, he placed these trees around a regular -gon that also has vertices, and the polygon vertices are labeled . More specifically, for each tree, he places each vertex of the tree onto some vertex of the polygon, and different vertices of the same tree cannot be placed onto the same polygon vertex.
He soon noticed that after doing this, every side and every diagonal of the polygon was “covered” by some tree edge. To make sure this was not a coincidence, he wants to reconstruct a set of placements, but it is too hard, so he asks you for help.
Formally, you need to construct an integer matrix () such that: for each , the sequence is a permutation of ; and for any , there exists an integer such that vertices and are connected by an edge in the original tree.
It can be proven that for any tree, a construction satisfying the conditions always exists.
Input Format
The first line contains an integer (), representing the number of vertices of the tree/polygon.
The next lines each contain two integers (), representing an edge of the tree.
Output Format
Output lines. On the -th line, output .
3
1 2
1 3
2 3 1
1 2 3
3 1 2
4
1 2
1 3
2 4
1 4 3 2
3 2 1 4
2 1 4 3
4 3 2 1
8
1 2
1 3
2 4
2 5
3 6
4 7
5 8
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
Hint
Subtasks
| Subtask | Score | Constraints |
|---|---|---|
| There exists a vertex such that every edge is connected to | ||
| The tree is a path | ||
| No additional constraints |
Translated by ChatGPT 5