#Q163. 「一本通 5.2 练习 4」叶子的染色
「一本通 5.2 练习 4」叶子的染色
Description
Original source: CQOI 2009
Given an unrooted tree with nodes, you can select a node with a degree greater than 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 , define as the color of the last colored node on the simple path from the root to . Given the value of each , design a coloring scheme that minimizes the number of colored nodes.
Input Format
The first line contains two integers and , representing the total number of nodes and the number of leaves, respectively. The nodes are numbered from to .
The next lines each contain a value of or , where represents black and represents white, corresponding to the values of in order.
The following lines each contain two integers and , indicating that there is an edge between nodes and .
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 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|