#Q163. 「一本通 5.2 练习 4」叶子的染色

「一本通 5.2 练习 4」叶子的染色

Description

Original source: CQOI 2009

Given an unrooted tree with mm nodes, you can select a node with a degree greater than 11 as the root. Then, color some nodes (the root, internal nodes, or leaves) either black or white. Your coloring scheme must ensure that every simple path from the root to any leaf node contains at least one colored node, even if it's the leaf itself.

For each leaf node uu, define cuc_u as the color of the last colored node on the simple path from the root to uu. Given the value of each cuc_u, design a coloring scheme that minimizes the number of colored nodes.

Input Format

The first line contains two integers mm and nn, representing the total number of nodes and the number of leaves, respectively. The nodes are numbered from 11 to mm.

The next nn lines each contain a value of 00 or 11, where 00 represents black and 11 represents white, corresponding to the values of c1,c2,,cnc_1, c_2, \cdots, c_n in order.

The following m1m-1 lines each contain two integers aa and bb, indicating that there is an edge between nodes aa and bb.

Output Format

Output a single integer, representing the minimum number of colored nodes.

Sample 1

5 3
0
1
0
1 4
2 5
4 5
3 5

2

Data Range and Hints

Data 11 22 33 44 55 66 77 88 99 1010
mm 1010 5050 100100 200200 400400 10001000 40004000 80008000 1000010000
nn 55 2323 5050 9898 197197 498498 20442044 40044004 50215021 49964996