#P10921. Happybob's Puzzle (UBC001A)

Happybob's Puzzle (UBC001A)

Problem Description

Given a tree with nn vertices, where every edge has length 11, you need to construct a permutation pp of 1∼n1 \sim n that satisfies:

  • For every integer ii with 1≤i<n1 \le i < n, the length of the simple path from vertex pip_i to vertex pi+1p_{i+1} is odd.

If a solution exists, output the lexicographically smallest permutation pp; otherwise, output −1-1.

Input Format

This problem contains multiple test cases.

The first line contains a positive integer tt, the number of test cases.

For each test case:

The first line contains a positive integer nn.

The next n−1n - 1 lines each contain two positive integers u,vu, v, indicating that there is an edge between vertices uu and vv.

Output Format

Output tt lines. Each line contains nn positive integers or a single integer −1-1, 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, 1≤t,n,∑n≤1051 \le t, n, \sum n \le 10^5, and it is guaranteed that 1≤u,v≤n1 \leq u, v \leq n and u≠vu \neq v. The input is guaranteed to form a tree. Here, ∑n\sum n denotes the sum of nn over all test cases.

Translated by ChatGPT 5