#LCA0000061. Màu sắc khác nhau (Distinct Colors)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Màu sắc khác nhau (Distinct Colors)
Distinct Colors
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
A tree of vertices is rooted at vertex . Vertex has integer color . The subtree of consists of itself and every descendant of when the tree is rooted at . For each vertex , count how many distinct colors occur in its subtree; repeated occurrences of a color count once.
Input
Line 1 contains . Line 2 contains . The next lines describe undirected edges .
Output
Print integers; the -th is the number of distinct colors in the subtree of .
Subtasks
General constraints: ; ; cạnh tạo thành một cây.
-
Subtask 1 (20 points): .
-
Subtask 2 (30 points): .
-
Subtask 3 (50 points): .
Examples
Input
5
2 3 2 2 1
1 2
1 3
3 4
3 5
Output
3 1 2 1 1
Explanation
The subtree of vertex contains colors ; that of vertex contains colors ; each leaf has one color.