QOJ.ac

QOJ

実行時間制限: 3 s メモリ制限: 1024 MB 満点: 100

#15123. 加油站

統計

Alex 正在一个简化的台湾高速公路系统模型上规划休息区的布局。该系统包含 $n$ 个互通立交(简称立交),由 $n - 1$ 条双向道路连接。该网络是连通的,且任意一对立交之间恰好存在一条最短路径。第 $i$ 条道路连接立交 $u_i$ 和 $v_i$,其长度为 $l_i$。

恰好可以建造 $k$ 个带有加油站的休息区,每个休息区都必须位于某个立交处。驾驶员可以从任意立交出发前往其他任意立交,且总是沿着唯一的最短路径行驶。他们在每次行程开始时都拥有满油箱,并且只能在设有休息区的立交处加油。

Alex 想知道最小的可能油箱容量 $d$ 是多少,使得能够合理布局这 $k$ 个休息区,从而确保任何驾驶员在任何行程中都不会耗尽燃油。在任何行程中,驾驶员在未经过休息区的情况下,沿路径连续行驶的距离绝不能超过 $d$ 个单位,这包括在行程的起点或终点(即从起点到第一个休息区,以及从最后一个休息区到终点的阶段)。目标是求出在最优放置休息区的情况下,满足上述条件的最小 $d$。

输入格式

第一行包含两个整数 $n, k$。

接下来的 $n - 1$ 行,每行包含三个整数 $u_i, v_i, l_i$,表示第 $i$ 条道路连接立交 $u_i$ 和 $v_i$,其长度为 $l_i$。

输出格式

输出一个整数,表示最小的可能油箱容量 $d$。

数据范围

  • $2 \le n \le 2 \times 10^5$
  • $0 \le k \le n$
  • $1 \le u_i, v_i \le n$
  • $1 \le l_i \le 10^9$
  • 保证输入的道路构成一棵树。

样例

输入样例 1

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

输出样例 1

5

输入样例 2

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

输出样例 2

3

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.