#L9132. [USACO23FEB] Watching Cowflix P
[USACO23FEB] Watching Cowflix P
P9132 [USACO23FEB] Watching Cowflix P
题目描述
Note: The time limit for this problem is 3s, 1.5x the default.
Bessie likes to watch shows on Cowflix, and she watches them in different places. Farmer John's farm can be represented as a tree with nodes, and for each node, either Bessie watches Cowflix there or she doesn't. It is guaranteed that Bessie watches Cowflix in at least one node.
Unfortunately, Cowflix is introducing a new subscription model to combat password sharing. In their new model, you can choose a connected component of size in the farm, and then you need to pay moonies for an account that you can use in that connected component. Formally, you need to choose a set of disjoint connected components so that every node where Bessie watches Cowflix must be contained within some . The cost of the set of components is , where is the number of nodes in component . Nodes where Bessie does not watch Cowflix do not have to be in any .
Bessie is worried that the new subscription model may be too expensive for her given all the places she visits and is thinking of switching to Mooloo. To aid her decision-making, calculate the minimum amount she would need to pay to Cowflix to maintain her viewing habits. Because Cowflix has not announced the value of , calculate it for all integer values of from to .
输入格式
The first line contains .
The second line contains a bit string where if Bessie watches Cowflix at node .
Then lines follow, each containing two integers and , which denotes an edge between and in the tree.
输出格式
The answers for each from to on separate lines.
输入输出样例 1
5
10001
1 2
2 3
3 4
4 5
4
6
8
9
10
输入输出样例 2
7
0001010
7 4
5 6
7 2
5 1
6 3
2 5
4
6
8
9
10
11
12
说明/提示
Explanation for Sample 1
For , it's optimal to have two accounts: . For , it's optimal to have one account: .
SCORING
- Inputs :
- Inputs : is connected to for all .
- Inputs :
- Inputs : No additional constraints.