#P3155. [CQOI2009] 叶子的染色

    ID: 2205 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划,dp2009重庆各省省选深度优先搜索,DFS

[CQOI2009] 叶子的染色

Description

Given an unrooted tree with mm nodes, you may choose any node with degree greater than 11 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 uu, define cuc_u as the color of the last colored node on the simple path from the root to uu. Given all values of cuc_u, design a coloring scheme that minimizes the number of colored nodes.

Input Format

The first line contains two integers m,nm, n, where nn is the number of leaves and mm is the total number of nodes. Nodes are numbered 1,2,,m1, 2, \ldots, m, and nodes 1,2,,n1, 2, \ldots, n are leaves.

Each of the next nn lines contains an integer 00 or 11 (00 means black, 11 means white), in order c1,c2,,cnc_1, c_2, \ldots, c_n.

Each of the next m1m-1 lines contains two integers a,ba, b, indicating that nodes aa and bb 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 1m1041 \le m \le 10^4, 1n50211 \le n \le 5021, 1a<bm1 \le a < b \le m.

Translated by ChatGPT 5