#P16189. [COI 2018] Paprike 胡椒
[COI 2018] Paprike 胡椒
Background
1 s, 1024 MB.
Problem Description
Krešo went to a local family farm and bought a string of peppers. The peppers are tied one by one with strings to form a “wreath”. This wreath consists of peppers and strings. Each string connects two different peppers, and any two peppers in the wreath are connected directly or indirectly through strings. In other words, these peppers and strings form a tree. With one cut of scissors, Krešo can cut a string and split one wreath into two smaller wreaths. These smaller wreaths can then be split further, and so on. Note that a single pepper (with no strings connected) is also considered a wreath.
Figure 1: The initial wreaths in the first two sample tests and their optimal cutting plans.
Each pepper’s spiciness is given by the famous Scoville scale, and is a non-negative integer. The spiciness of a wreath is the sum of the spiciness values of all peppers in it. Krešo wants to prepare lunch for high school students participating in informatics competitions. He knows that an average high school student can eat at most a wreath with spiciness not exceeding . If the spiciness is greater than , he would have to call a doctor and a minor’s lawyer.
Please compute the minimum number of cuts needed to split the initial wreath into several wreaths, each with spiciness at most .
Input Format
The first line contains two integers and , representing the number of peppers and the maximum allowed spiciness of a single wreath. The peppers are numbered from to . The second line contains integers , where is the spiciness of pepper . The next lines each contain two different integers and , indicating that peppers and are directly connected by a string in the initial wreath. The peppers and strings form a tree.
Output Format
Output the minimum number of cuts required.
5 5
1 2 3 4 5
1 2
2 3
3 4
4 5
3
10 10
3 4 2 3 7 1 4 1 5 2
1 2
2 4
5 2
6 3
3 1
6 7
9 7
8 6
8 10
3
6 9
5 4 1 3 3 3
3 1
3 5
4 3
4 2
2 6
2
Hint
Constraints
In all subtasks, it holds that and .
Subtasks
::cute-table{three} |ID |Score |Constraints | |:-:|:--:|:--------:| |||| |||, and peppers are connected in order to pepper .| |||| ||||
Translation source: GPT 4.1 mini.
Translated by ChatGPT 5