#P10531. Maximum Christmas Trees

    ID: 12549 Type: Default 1000ms 256MiB

Maximum Christmas Trees

Maximum Christmas Trees

You are given a tree with n vertices numbered from 1 to n. Each vertex i is assigned a color denoted by \( col_i \), and different \( col_i \) represent different colors.

Little L wants to partition the tree into several disjoint connected components. A connected component can be used to make a Christmas tree if and only if it contains at least \( k \) different colors. Determine the maximum number of Christmas trees that can be produced by partitioning the tree optimally.

Note: A partition here means that every vertex of the original tree belongs to exactly one connected component, and each component is obtained by removing some subset of edges.

inputFormat

The first line contains two integers \( n \) and \( k \) separated by a space.

The second line contains \( n \) integers: \( col_1, col_2, ..., col_n \) representing the colors of the vertices.

Each of the next \( n-1 \) lines contains two integers \( u \) and \( v \), indicating that there is an edge between vertices \( u \) and \( v \) in the tree.

outputFormat

Output a single integer which is the maximum number of connected components (Christmas trees) that can be obtained such that each has at least \( k \) distinct colors.

sample

3 2
1 2 3
1 2
2 3
1

</p>