CF1725J.Journey
普及/提高-
通过率:0%
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 N cities numbered from 1 to N . The cities are connected to each other with N−1 two-directional roads, with the i -th road connecting cities Ui and Vi , and taking a time of Wi 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.
输入格式
The first line contains a single integer N ( 1≤N≤105 ) — the number of cities in Londonesia.
The i -th of the next N−1 lines contains three integers Ui , Vi , and Wi ( 1≤Ui,Vi≤N , 1≤Wi≤109 ) — a two-directional road that connects cities Ui and Vi that takes Wi hours to be traversed. The roads in Londonesia form a tree.
输出格式
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→1teleport4→3 .
In the second example, the journey that has the minimum time is 3→1→4→1→2teleport5 .