#P10531. [XJTUPC 2024] 圣诞树

[XJTUPC 2024] 圣诞树

Problem Description

There is a tree with nn nodes, numbered from 11 to nn. Each node of the tree has a color, denoted by colicol_i. Different colicol_i 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 kk 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 n,kn, k (1kn2×1051\le k \le n \le 2\times 10^5), separated by spaces.

The second line contains nn positive integers colicol_i (1colin1\le col_i \le n), representing the color of node ii, separated by spaces.

The next n1n-1 lines each contain two positive integers x,yx, y (1x,yn1\le x,y \le n, xyx \neq y), 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