CF1725J.Journey

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

One day, Pak Chanek who is already bored of being alone at home decided to go traveling. While looking for an appropriate place, he found that Londonesia has an interesting structure.

According to the information gathered by Pak Chanek, there are NN cities numbered from 11 to NN. The cities are connected to each other with N−1N-1 two-directional roads, with the ii-th road connecting cities UiU_i and ViV_i, and taking a time of WiW_i hours to be traversed. In other words, Londonesia's structure forms a tree.

Pak Chanek wants to go on a journey in Londonesia starting and ending in any city (not necessarily the same city) such that each city is visited at least once with the least time possible. In order for the journey to end quicker, Pak Chanek also carries an instant teleportation device for moving from one city to any city that can only be used at most once. Help Pak Chanek for finding the minimum time needed.

Notes:

  • Pak Chanek only needs to visit each city at least once. Pak Chanek does not have to traverse each road.
  • In the journey, a city or a road can be visited more than once.

一天,早已厌倦独自待在家中的 Pak Chanek 决定外出旅行。在寻找合适目的地的过程中,他发现伦多尼西亚(Londonesia)具有一个有趣的结构。

根据 Pak Chanek 收集到的信息,共有 NN 座城市,编号从 11 到 NN。这些城市之间由 N−1N-1 条双向道路连接,其中第 ii 条道路连接城市 UiU_i 和 ViV_i, traversing 该道路耗时 WiW_i 小时。换言之,伦多尼西亚的结构构成一棵树。

Pak Chanek 希望在伦多尼西亚开展一次旅行:起点和终点可以是任意城市(未必相同),且需确保每座城市至少被访问一次,并使得总耗时尽可能少。为了更快结束旅程,Pak Chanek 还随身携带了一台瞬移装置,可将他从一座城市瞬间传送至任意另一座城市,但该装置最多只能使用一次。请帮助 Pak Chanek 求出所需的最少时间。

注意:

  • Pak Chanek 只需确保每座城市至少被访问一次;他无需遍历每一条道路。
  • 在整个旅程中,一座城市或一条道路均可被多次访问。

输入格式

The first line contains a single integer NN (1≤N≤1051 \le N \le 10^5) — the number of cities in Londonesia.

The ii-th of the next N−1N-1 lines contains three integers UiU_i, ViV_i, and WiW_i (1≤Ui,Vi≤N1 \le U_i, V_i \le N, 1≤Wi≤1091 \le W_i \le 10^9) — a two-directional road that connects cities UiU_i and ViV_i that takes WiW_i hours to be traversed. The roads in Londonesia form a tree.

第一行包含一个整数 NN(1≤N≤1051 \le N \le 10^5)—— 伦多尼亚的城市数量。

接下来的 N−1N-1 行中,第 ii 行包含三个整数 UiU_i、ViV_i 和 WiW_i(1≤Ui,Vi≤N1 \le U_i, V_i \le N,1≤Wi≤1091 \le W_i \le 10^9)—— 表示一条双向道路,连接城市 UiU_i 和 ViV_i, traversing 该道路耗时 WiW_i 小时。伦多尼亚的道路构成一棵树。

输出格式

Output one integer, which represents the minimum time in hours that is needed to visit each city at least once.

输出一个整数,表示至少访问每个城市一次所需的最短时间(单位:小时)。

输入输出样例

  • 输入#1

    4
    1 2 4
    2 3 5
    3 4 4

    输出#1

    8
  • 输入#2

    5
    1 2 45
    1 3 50
    1 4 10
    1 5 65

    输出#2

    115

说明/提示

In the first example, the journey that has the minimum time is 2→1→teleport4→32 → 1 \xrightarrow{\text{teleport}} 4 → 3.

In the second example, the journey that has the minimum time is 3→1→4→1→2→teleport53 → 1 → 4 → 1 → 2 \xrightarrow{\text{teleport}} 5.

在第一个例子中,耗时最少的路径为 2→1→teleport4→32 → 1 \xrightarrow{\text{teleport}} 4 → 3。

在第二个例子中,耗时最少的路径为 3→1→4→1→2→teleport53 → 1 → 4 → 1 → 2 \xrightarrow{\text{teleport}} 5。

输入解题思路,AI测评打分。不知道怎么写?

首页