#P9132. [USACO23FEB] Watching Cowflix P
[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.
题目大意
Bessie 喜欢在 Cowflix 上看节目,并且喜欢在农场里的不同地方看。
Farmer John 的农场可以被描述成一颗 个节点的树,并且 Bessie 只可能在树上的一些指定的节点处看节目。每个节点是否要看节目将在初始时给定;保证至少在一个节点处会看节目。
不幸的是,Cowflix 为了避免奶牛们使用公用账号,采取了一个新的会员策略:
- Bessie 将多次付款,每次选择树上任意一个大小为 的连通块,为其支付 的代价,才能够在这些位置看节目。
换言之,Bessie 将选取若干连通块 ,支付 的代价,才可以在这些连通块的各个节点处看节目;即,被指定的节点必须被某个连通块包含,不被指定的节点不必被包含。
Bessie 觉得这个策略的代价太昂贵了,考虑是否要改在 Mooloo 上看节目。为了帮助其决策,你应当告诉之 取遍 时看节目的最小总代价。
。
5
10001
1 2
2 3
3 4
4 5
4
6
8
9
10
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.