Interesting Outing
시간 제한10초메모리 제한1024 MB
가중치가 있는 트리에서 모든 정점을 한 번 이상 방문하는 가장 저렴한 보행 경로의 비용을 구한다.
문제
You are hosting visitors from out of town, and want to take them out and show them the most interesting places in town.
There are interesting sights you want to tour. You have identified interesting methods of transportation. Each method of transportation bidirectionally connects a pair of sights. Luckily, there is exactly one way to get from any interesting sight to another without using any transportation method more than once.
You know how much it would cost for the group to use each transportation method one time (you pay once per use). You can decide the starting and ending sights of the tour (they can be the same or different sights). You do not need to worry about the cost of getting to the starting point nor coming back from the ending point, only the cost of transportation between sights during the tour. What is the cheapest way to see all sights at least once each?
입력
The first line of the input gives the number of test cases, . test cases follow. Each test case starts with a line containing a single integer , the number of sights you want to tour. Then, lines follow. The -th of these lines contains three integers , , and , representing that the -th method of transportation can take your group from sight to sight or from sight to sight for a cost of coins per usage.
출력
For each test case, output one line containing Case #x: y, where is the test case number (starting from 1) and is an integer representing the minimum cost of a tour that visits each sight at least once.
제한
- .
- , for all .
- It is possible to travel between any pair of sights using only the methods of transportation given in the input. (This and the previous limits imply the sights and transportation methods form an unrooted tree.)
- for all .
힌트
In Sample Case #1 (as seen below), an optimal route (marked with a red line in the picture above) goes through the following sights: .

In Sample Case #2 (as seen above), the only change compared with the setup in Sample Case #1 is that the transportation between sights and got more expensive: from to . The route costs in this scenario and it is not optimal. The optimal route is instead (also marked in red in the picture).

Notice in Sample Case #3 that the answer may be larger than .