#P7920. [Kubic] Permutation
[Kubic] Permutation
Description
For a permutation of , define as an undirected graph constructed by the following method:
- For each , find the largest such that , and then add an edge between and . If no such exists, do not add an edge.
You are given a tree with nodes.
Call a good permutation if and only if is isomorphic to .
If a good permutation exists, output the lexicographically largest one. Otherwise, output .
Two undirected graphs are isomorphic if and only if there exists a permutation of such that $\forall (u,v)\in G_1,(q_u,q_v)\in G_2,\forall (u,v)\notin G_1,(q_u,q_v)\notin G_2$.
Input Format
The first line contains an integer .
The next lines each contain two integers , indicating that there is an edge between and .
Output Format
Output one line with integers representing the answer, or output a single number indicating that there is no solution.
5
1 2
1 3
2 4
2 5
1 5 4 2 3
9
1 2
2 3
1 4
4 5
5 6
1 7
7 8
8 9
1 9 2 6 7 8 3 4 5
Hint
For of the data, .
| Score | Special Property | ||
|---|---|---|---|
| None | |||
| No special limit | The tree degenerates into a chain | ||
| The number of nodes with degree is | |||
| None | |||
| No special limit |
Note: the node labels in the sample explanations are the indices in .
Sample Explanation 1
The shape of is as follows:

It can be proven that there is no better solution.
Sample Explanation 2
The shape of is as follows:

It can be proven that there is no better solution.
Translated by ChatGPT 5
京公网安备 11011102002149号