#P10531. [XJTUPC 2024] 圣诞树
[XJTUPC 2024] 圣诞树
Problem Description
There is a tree with nodes, numbered from to . Each node of the tree has a color, denoted by . Different represent different colors.
Little L wants to use this tree to make many Christmas trees. A connected component can be made into a Christmas tree if and only if it has at least different colors. Little L will split the tree into several pairwise disjoint connected components, and take those components that satisfy the condition to make Christmas trees.
Given the shape of the tree, what is the maximum number of Christmas trees that can be made?
Input Format
The first line contains two positive integers (), separated by spaces.
The second line contains positive integers (), representing the color of node , separated by spaces.
The next lines each contain two positive integers (, ), representing an edge in the tree, separated by spaces.
Output Format
Output one line with one integer, representing your answer.
4 2
1 2 3 4
1 2
1 3
1 4
1
4 2
1 2 3 4
1 2
2 3
3 4
2
Hint
Translated by ChatGPT 5