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
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
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 vertices, assign distinct labels such that is not prime for each edge . Output any valid assignment, or -1 if impossible.
Input
First line , followed by undirected edges.
Output
Print the labels, or -1.
Subtask
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
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.