Codeforces Round 992 (Div. 2)
D
Non Prime Tree
Codeforces
1900
原题
← CE →
翻译中…

You are given a tree with $n$ vertices.

翻译中…

You need to construct an array $a_1, a_2, \ldots, a_n$ of length $n$, consisting of unique integers from $1$ to $2 \cdot n$, and such that for each edge $u_i \leftrightarrow v_i$ of the tree, the value $|a_{u_i} - a_{v_i}|$ is not a prime number.

翻译中…

Find any array that satisfies these conditions, or report that there is no such array.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the number of vertices in the tree.

翻译中…

The next $n - 1$ lines contain the edges of the tree, one edge per line. The $i$-th line contains two integers $u_i$ and $v_i$ ($1 \le u_i, v_i \le n$; $u_i \neq v_i$), denoting the edge between the nodes $u_i$ and $v_i$.

翻译中…

It's guaranteed that the given edges form a tree.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10 ^ 5$.

翻译中…

Output

翻译中…

For each test case, if an array that satisfies the conditions exists, print its elements $a_1, a_2, \ldots, a_n$. Otherwise, print $-1$.

翻译中…

Note

翻译中…

The possible answers are shown below. Instead of the vertex numbers, the corresponding elements of the array $a$ are written in them.

翻译中…

The image of the tree in the first test case image

翻译中…

The image of the tree in the second test case image

翻译中…

样例

Input #1
2
5
1 2
2 3
2 4
3 5
7
1 2
1 3
2 4
3 5
3 6
3 7
Output #1
2 10 1 6 5
8 7 12 1 4 6 3
InputCopy OutputCopy
题目信息
题号
2040D
时间限制
2 s
内存限制
256 MB
标签
暴力
构造
DFS 及类似
贪心
数论
树
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。