QOJ.ac

QOJ

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

#3281. 阿伽门农的奥德赛

Statistiques

迈锡尼的伟大国王阿伽门农正在奥利斯集结军队,准备航向特洛伊海岸,这时他得到了女神阿耳忒弥斯的启示。在启示中,阿伽门农发现他无意中杀死了一头阿耳忒弥斯神圣的鹿,现在女神发誓要让阿伽门农在前往特洛伊的航程中饱受折磨。

在前往特洛伊的途中,阿伽门农计划在克里特岛停留,为他强大的军队收集资源。如果阿耳忒弥斯发现了阿伽门农所走的航线,她就会利用神力阻断这些航线上的风,使阿伽门农和他的船员陷入困境。作为阿伽门农的忠实顾问,你现在必须帮助他设计一条克里特岛之间的路径,在不让阿耳忒弥斯发现所走航线的前提下,为军队提供最大数量的资源。

克里特岛的 $N$ 个岛屿通过 $N - 1$ 条海上航线相互连接。沿着每条航线,阿伽门农可以获得一定数量的资源。然而,如果一条航线被使用超过 $k$ 次,阿耳忒弥斯就会察觉到阿伽门农在该航线上的行踪,并阻断该航线上的风。因此,一个可行的计划不能使用任何航线超过 $k$ 次。

已知阿伽门农可以从克里特岛的任意岛屿出发并结束航行,请给出一个可行的计划,使阿伽门农获得的资源收益最大化。注意,阿伽门农只能在第一次使用某条海上航线时收集资源。重复使用该航线时,他不会获得额外的资源。

示例地图

输入格式

输入的第一行包含两个整数 $N$ ($1 \le N \le 2 \cdot 10^5$) 和 $k$ ($1 \le k \le 10^9$),分别表示克里特岛的岛屿数量,以及在不被阿耳忒弥斯发现的情况下,单条航线最多可被使用的次数。保证克里特岛的岛屿通过这些海上航线连通。

接下来的 $N - 1$ 行描述了海上航线。每行包含 3 个整数 $u, v$ ($1 \le u, v \le N, u \neq v$) 和 $c$ ($1 \le c \le 10^9$),表示该海上航线连接岛屿 $u$ 和 $v$,且阿伽门农沿着这条航线可以获得 $c$ 单位的资源。所有海上航线都是双向的,即它们可以用于从岛屿 $u$ 到 $v$,或从岛屿 $v$ 到 $u$。

输出格式

输出一个整数,表示阿伽门农在满足题目描述的可行计划下,所能获得的最大资源总量。

样例

输入 1

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

输出 1

14

说明 1

克里特岛有 5 个岛屿,通过 4 条航线连接,如图所示:第一条连接岛屿 1 和 2,允许阿伽门农获得 3 单位资源,依此类推。在这个群岛中,阿伽门农的最佳计划是从岛屿 4 出发,访问岛屿 1(沿着 $4 \to 1$ 的航线获得 5 单位资源),然后以岛屿 5 结束他的路径(沿着 $1 \to 5$ 的航线获得 9 单位资源),总共获得了 14 单位资源。

输入 2

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

输出 2

18

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.