#P15048. [UOI 2022 II Stage] 树 2
[UOI 2022 II Stage] 树 2
Problem Description
Cossack Moustache saw a tree on his way home from the railway, and came up with a problem.
You are given a tree with vertices, and each edge has a weight. Initially, all vertices are white. We call an edge a bright edge if and only if it connects two white vertices. Please answer queries:
- What is the minimum number of vertices that need to be recolored to black so that the sum of weights of all bright edges does not exceed ?
Please help Cossack Moustache solve this problem.
Input Format
The first line contains three integers , , and (, , ), which represent the number of vertices, the number of queries, and the subtask ID, respectively.
In the next lines, each line contains three integers , , and (, ), which describe an edge between the two vertices and its weight.
The fourth line contains integers ().
Output Format
Output integers , where is the answer to the -th query.
3 5 0
1 2 3
1 3 2
3 5 1 2 0
1 0 1 1 1
4 4 0
1 3 10
2 1 15
1 4 50
75 50 72 19
0 1 1 1
5 8 0
1 4 5
2 1 18
1 3 9
3 5 27
5 15 7 19 20 58 35 27
2 2 2 2 2 1 1 1
Hint
Sample Explanation
In the first sample, if , we can keep all vertices white. Then all edges are bright edges, and the sum of their weights is . If , we can recolor vertex to black, so there will be no bright edges, and thus the sum of weights is . In both cases, the sum of weights of bright edges does not exceed , and the number of recolored vertices is minimal.
Scoring
- (5 points): ; the answer is guaranteed to be at most .
- (9 points): ; the answer is guaranteed to be at most .
- (28 points): ; .
- (14 points): ; .
- (21 points): .
- (23 points): No additional constraints.
Translated by DeepSeek V3.
Translated by ChatGPT 5