PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000149. Gán nhãn cây không có hiệu nguyên tố (Non Prime Tree)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Gán nhãn cây không có hiệu nguyên tố (Non Prime Tree)

Non Prime Tree

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given a tree with nn vertices, assign distinct labels ai∈[1,2n]a_i\in[1,2n] such that ∣au−av∣|a_u-a_v| is not prime for each edge (u,v)(u,v). Output any valid assignment, or -1 if impossible.

Input

First line nn, followed by n−1n-1 undirected edges.

Output

Print the nn labels, or -1.

Subtask

  • Subtask 1 (20 points): 2≤n≤502\le n\le50.
  • Subtask 2 (30 points): 2≤n≤50002\le n\le5000.
  • Subtask 3 (50 points): 2≤n≤2000002\le n\le200000.

Example

Input

5
1 2
2 3
2 4
3 5

Output

1 2 3 6 4

Explanation

Each label lies in the allowed range and no two labels coincide. Check the absolute difference at each of the four input edges: each is 1 or a composite number.