#P3155. [CQOI2009] 叶子的染色
[CQOI2009] 叶子的染色
Description
Given an unrooted tree with nodes, you may choose any node with degree greater than as the root, and then color some nodes (the root, internal nodes, and leaves are all allowed) black or white.
Your coloring must ensure that on the simple path from the root to each leaf, there is at least one colored node (possibly 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 all values of , design a coloring scheme that minimizes the number of colored nodes.
Input Format
The first line contains two integers , where is the number of leaves and is the total number of nodes. Nodes are numbered , and nodes are leaves.
Each of the next lines contains an integer or ( means black, means white), in order .
Each of the next lines contains two integers , indicating that nodes and are connected by an edge.
Output Format
Output a single integer: the minimum number of colored nodes.
5 3
0
1
0
1 4
2 5
4 5
3 5
2
Hint
Constraints
For all testdata, it is guaranteed that , , .
Translated by ChatGPT 5
京公网安备 11011102002149号