CF61D.Eternal Victory
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Valerian was captured by Shapur. The victory was such a great one that Shapur decided to carve a scene of Valerian's defeat on a mountain. So he had to find the best place to make his victory eternal!
He decided to visit all n cities of Persia to find the best available mountain, but after the recent war he was too tired and didn't want to traverse a lot. So he wanted to visit each of these n cities at least once with smallest possible traverse. Persian cities are connected with bidirectional roads. You can go from any city to any other one using these roads and there is a unique path between each two cities.
All cities are numbered 1 to n. Shapur is currently in the city 1 and he wants to visit all other cities with minimum possible traverse. He can finish his travels in any city.
Help Shapur find how much He should travel.
瓦勒里安被沙普尔俘获。这场胜利如此辉煌,以至于沙普尔决定在一座山上雕刻瓦勒里安战败的场景,以此使他的胜利永垂不朽!
他决定遍访波斯的全部 n 座城市,以寻找最合适的山峰,但鉴于刚刚结束的战争,他已精疲力竭,不愿过多奔波。因此,他希望以最小的总行程访问这 n 座城市中的每一座至少一次。波斯的城市由双向道路连接;任意两座城市之间均可通过这些道路相互到达,且任意两座城市之间存在唯一路径。
所有城市编号为 1 到 n。沙普尔当前位于城市 1,他希望以最小可能的总行程访问其余所有城市(即全部 n 座城市),且旅行可在任意城市结束。
请帮助沙普尔计算他所需行走的最短总路程。
输入格式
First line contains a single natural number n (1 ≤ n ≤ 105) — the amount of cities.
Next n - 1 lines contain 3 integer numbers each x__i, y__i and w__i (1 ≤ x__i, y__i ≤ n, 0 ≤ w__i ≤ 2 × 104). x__i and y__i are two ends of a road and w__i is the length of that road.
第一行包含一个正整数 n(1≤n≤105)—— 城市的数量。
接下来的 n−1 行,每行包含三个整数 xi、yi 和 wi(1≤xi,yi≤n,0≤wi≤2×104)。其中 xi 和 yi 是一条道路的两个端点,wi 是该道路的长度。
输出格式
A single integer number, the minimal length of Shapur's travel.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
一个整数,表示沙普尔旅行的最短长度。
请注意,在 C++ 中读写 64 位整数时,请勿使用 %lld 格式说明符。推荐使用 cout(也可使用 %I64d)。
输入输出样例
输入#1
3 1 2 3 2 3 4
输出#1
7
输入#2
3 1 2 3 1 3 3
输出#2
9
输入解题思路,AI测评打分。不知道怎么写?