#P10921. Happybob's Puzzle (UBC001A)
Happybob's Puzzle (UBC001A)
Problem Description
Given a tree with vertices, where every edge has length , you need to construct a permutation of that satisfies:
- For every integer with , the length of the simple path from vertex to vertex is odd.
If a solution exists, output the lexicographically smallest permutation ; otherwise, output .
Input Format
This problem contains multiple test cases.
The first line contains a positive integer , the number of test cases.
For each test case:
The first line contains a positive integer .
The next lines each contain two positive integers , indicating that there is an edge between vertices and .
Output Format
Output lines. Each line contains positive integers or a single integer , representing the answer for that test case.
2
3
1 2
2 3
7
1 2
1 3
2 4
2 5
3 6
3 7
1 2 3
-1
Hint
Constraints
For all testdata, , and it is guaranteed that and . The input is guaranteed to form a tree. Here, denotes the sum of over all test cases.
Translated by ChatGPT 5