QOJ.ac

QOJ

حد الوقت: 3 s حد الذاكرة: 512 MB مجموع النقاط: 110

#2469. 公园

الإحصائيات

市政府决定通过修建新公园来美化城市景观。为了让公园不仅美观而且实用,他们需要仔细选择在哪些街区修建公园,以便其他街区的孩子们附近至少有一个公园。

该城市由 $n$ 个街区组成,这些街区由 $n - 1$ 条特定长度的道路连接。任意两个街区之间都存在唯一的路径。换句话说,这些街区和道路构成了一棵树。必须在不同的街区中修建恰好 $k$ 个公园,使得其他街区到其最近公园的距离尽可能小。更准确地说,市政府希望最小化“从一个街区到其最近公园的距离”的最大值。

请帮助市政府确定应该在哪些街区修建公园,并确定从一个街区到其最近公园的最大距离。

输入格式

第一行包含两个正整数 $n$ 和 $k$ ($1 \le k \le n \le 200\,000$),分别表示街区的数量和公园的数量。

接下来的 $n - 1$ 行,第 $i$ 行包含正整数 $a_i, b_i$ 和 $w_i$ ($1 \le a_i, b_i \le n, 1 \le w_i \le 10^9$),表示编号为 $a_i$ 和 $b_i$ 的街区之间由一条长度为 $w_i$ 的道路连接。

输出格式

第一行输出题目要求最小化的最大距离。

第二行输出 $k$ 个正整数,表示修建公园的街区编号。如果存在多种解,输出任意一种即可。

子任务

子任务 分值 约束
1 10 $1 \le n \le 20$
2 10 $k = 1$
3 30 对于所有 $1 \le i \le n - 1$,有 $a_i = i, b_i = i + 1$
4 60 无附加约束

样例

样例输入 1

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

样例输出 1

8
4 5 8

样例输入 2

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

样例输出 2

3
2 4

样例输入 3

7 4
1 3 1
1 4 1
2 3 1
5 3 1
4 7 1
4 6 1

样例输出 3

1
3 4 1 2

说明

第三个样例的说明: 如果仅在街区 3 和 4 修建公园,最大距离不会改变,但市政府希望修建恰好 $k$ 个公园,因此需要在其他地方再修建两个。

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.