#P16189. [COI 2018] Paprike 胡椒

    ID: 18102 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>贪心2018树形 DPCOI(克罗地亚)

[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 nn peppers and (n−1)(n - 1) 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 kk. If the spiciness is greater than kk, 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 kk.

Input Format

The first line contains two integers nn and kk, representing the number of peppers and the maximum allowed spiciness of a single wreath. The peppers are numbered from 11 to nn. The second line contains nn integers h1,h2,…,hnh_1, h_2, \ldots, h_n, where hjh_j is the spiciness of pepper jj. The next n−1n - 1 lines each contain two different integers xx and y (1≤x,y≤n)y\ (1 \le x, y \le n), indicating that peppers xx and yy 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 n≥2n \ge 2 and 0≤h1,h2,…,hn≤k≤3 000 0000 \le h_1, h_2, \ldots, h_n \le k \le 3\,000\,000.

Subtasks

::cute-table{three} |ID |Score |Constraints | |:-:|:--:|:--------:| |11|1111|n≤15n \le 15| |22|1313|n≤100 000n \le 100\,000, and peppers x=1,...,n−1x = 1, ..., n - 1 are connected in order to pepper x+1x + 1.| |33|2727|n≤1 000n \le 1\,000| |44|4949|n≤1 000 000n \le 1\,000\,000|

Translation source: GPT 4.1 mini.

Translated by ChatGPT 5