#P8399. [CCC 2022 S5] Good Influencers
[CCC 2022 S5] Good Influencers
Problem Description
Given a tree, node has a weight . Some nodes are blue Y, and some nodes are white N. In each operation, you can choose a blue node and recolor all directly adjacent white nodes to blue. The cost of this operation is the weight of the chosen blue node.
Find the minimum total cost to recolor the entire tree to blue.
It is guaranteed that there is at least one white node and at least one blue node.
Input Format
The first line contains an integer , the size of the tree.
The next lines each contain two integers , , meaning that and are directly connected.
The next line contains characters indicating the initial color of each node.
The next line contains integers indicating the weight of each node.
Output Format
One line containing the minimum total cost.
4
1 2
2 3
3 4
YNYN
4 3 6 2
6
15
1 5
5 2
2 15
15 4
2 10
8 3
3 1
1 6
11 6
12 6
11 9
11 14
12 7
13 7
NNYYYNYYNNNNNNN
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
6
Hint
For of the testdata: , , and .
For another of the testdata: , .
For of the testdata: , .
Translated by ChatGPT 5