QOJ.ac

QOJ

Limite de temps : 2 s Limite de mémoire : 1024 MB Points totaux : 100

#1960. 逻辑仓库 2

Statistiques

KOPANG 是韩国最大的在线供应商之一,并首次推出了所谓的“早间配送”服务。为了应对日益增长的需求,KOPANG 计划建立新的物流仓库。物流仓库的位置必须在距离客户一定的范围内,以保证 KOPANG 对客户承诺的配送时间。

物流网络被建模为一个连通树 $T$。$T$ 的每个节点代表一个区域(如韩国的一个城市或省份),$T$ 的每条边代表连接两个区域的运输道路。KOPANG 希望选择一个或多个 $T$ 的节点作为物流仓库,以满足距离限制。在选择之前,KOPANG 通过充分研究确定了一个距离参数 $K$。现在,KOPANG 希望选择最少数量的节点,使得 $T$ 中每个节点到其最近的所选节点(仓库)的距离最多为 $K$。两个节点 $u$ 和 $v$ 之间的距离是 $T$ 中连接 $u$ 和 $v$ 的(唯一)路径上的边数。注意,如果 $u = v$,则距离定义为零。

例如,图 G.1 展示了一个包含九个节点和八条边的树 $T$。对于 $K = 1$,如果三个仓库分别位于节点 2、5 和 8(如图 G.1 (a) 中红色圆圈所示),则 $T$ 中每个节点到最近仓库的距离最多为 1。两个仓库不足以满足距离限制,因此三个仓库是最小值。对于 $K = 2$,仍然需要三个仓库;$K = 1$ 时位于节点 2、5 和 8 的仓库同样适用于 $K = 2$。当然,满足最小仓库数量的位置并不唯一;如图 G.1 (b) 所示,位于节点 4、7 和 1 的三个仓库也满足 $K = 2$ 时的距离限制。

给定一个连通树 $T$ 和一个正整数 $K$,编写一个程序来选择最少数量的节点(仓库),使得 $T$ 中每个节点到其最近仓库的距离最多为 $K$。

图 G.1 标记为红色圆圈的节点即为选定的仓库。

输入格式

程序从标准输入读取数据。输入的第一行包含两个整数 $n$ 和 $K$ ($1 \le K \le n \le 10^5$),其中 $n$ 是连通树的节点数,且树中每个节点到其最近所选节点的距离最多为 $K$。接下来的 $n - 1$ 行给出了边信息;第 $i$ 行包含两个正整数,表示第 $i$ 条边的两个端点索引。节点索引从 1 到 $n$。

输出格式

程序将结果写入标准输出。输出仅一行,包含满足给定树和距离参数 $K$ 的距离限制所需的最小物流仓库节点数量。

样例

样例输入 1

9 1
2 1
7 3
3 4
4 5
6 5
7 8
3 2
8 9

样例输出 1

3

样例输入 2

9 2
2 1
7 3
3 4
4 5
6 5
7 8
3 2
8 9

样例输出 2

3

样例输入 3

9 8
2 1
7 3
3 4
4 5
6 5
7 8
3 2
8 9

样例输出 3

1

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.