QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 1024 MB Total points: 100

#18594. Paprike

Statistics

Krešo 去当地的一家农场买了一串用细绳整齐地连接在一起的辣椒,这被称为“辣椒圈”(wreath)。在本题中,一个辣椒圈由 $n$ 个辣椒和 $n - 1$ 根细绳组成。每根细绳连接两个不同的辣椒,且辣椒圈中的任意两个辣椒都通过细绳(直接或间接)相连。因此,辣椒和细绳构成了一棵树。

用剪刀剪一刀,Krešo 就可以剪断一根细绳,将一个辣椒圈分成两个较小的辣椒圈,这两个较小的辣椒圈还可以继续被分割成更小的辣椒圈,依此类推。需要注意的是,不与任何其他东西相连的单个辣椒也构成一个辣椒圈。

图 1:前两个样例的初始辣椒圈以及最优剪法。

单个辣椒的辣度是用所谓的史高维尔指标(Scoville scale)来衡量的,并表示为一个非负整数。一个辣椒圈的辣度是它所包含的所有单个辣椒的辣度之和。

Krešo 想要给信息学竞赛后高中生的午餐加点料,他知道普通高中生最多只能吃下辣度不超过 $k$ 的辣椒圈,否则他们就需要去看医生并找少年律师。

请确定最少需要剪多少刀,才能使 Krešo 将初始的辣椒圈分割成若干个辣度最多为 $k$ 的辣椒圈。

输入格式

第一行包含两个整数 $n$ 和 $k$ —— 辣椒的数量和单个辣椒圈允许的最大辣度。辣椒用 $1$ 到 $n$ 的数字表示。

下一行包含 $n$ 个整数 $h_1, h_2, \dots, h_n$ —— 其中 $h_j$ 是第 $j$ 个辣椒的辣度。

接下来的 $n - 1$ 行,每行包含两个不同的整数 $x$ 和 $y$ ($1 \le x, y \le n$) —— 表示在初始辣椒圈中直接用细绳相连的两个辣椒的编号。如题所述,辣椒和细绳构成一棵树。

输出格式

输出最少需要剪的刀数。

子任务

在所有子任务中,均满足 $n \ge 2$ 且 $0 \le h_1, h_2, \dots, h_n \le k \le 3\,000\,000$。

子任务 分值 限制
1 11 $n \le 15$
2 13 $n \le 100\,000$,每个辣椒 $x = 1, \dots, n - 1$ 与辣椒 $x + 1$ 相连。
3 27 $n \le 1\,000$
4 49 $n \le 100\,000$

样例

输入样例 1

5 5
1 2 3 4 5
1 2
2 3
3 4
4 5

输出样例 1

3

输入样例 2

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

输出样例 2

3

输入样例 3

6 9
5 4 1 3 3 3
3 1
3 5
4 3
4 2
2 6

输出样例 3

2

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.