| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 10 초 (추가 시간 없음) | 1024 MB (추가 메모리 없음) | 26 | 16 | 15 | 60.000% |
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 $N$ interesting sights you want to tour. You have identified $N-1$ 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, $T$. $T$ test cases follow. Each test case starts with a line containing a single integer $N,ドル the number of sights you want to tour. Then, $N-1$ lines follow. The $i$-th of these lines contains three integers $A_i,ドル $B_i,ドル and $C_i,ドル representing that the $i$-th method of transportation can take your group from sight $A_i$ to sight $B_i$ or from sight $B_i$ to sight $A_i$ for a cost of $C_i$ coins per usage.
For each test case, output one line containing Case #x: y, where $x$ is the test case number (starting from 1) and $y$ is an integer representing the minimum cost of a tour that visits each sight at least once.
3 6 1 3 10 4 5 10 3 4 10 4 6 20 2 3 30 6 1 3 35 4 5 10 3 4 10 4 6 20 2 3 30 5 1 3 1000000000 2 3 1000000000 3 4 1000000000 3 5 1000000000
Case #1: 100 Case #2: 145 Case #3: 6000000000
In Sample Case #1 (as seen below), an optimal route (marked with a red line in the picture above) goes through the following sights: 2,3,1,3,4,5,4,6ドル$.
In Sample Case #2 (as seen above), the only change compared with the setup in Sample Case #1 is that the transportation between sights 1ドル$ and 3ドル$ got more expensive: from 10ドル$ to 35ドル$. The route 2,3,1,3,4,5,4,6ドル$ costs 150ドル$ in this scenario and it is not optimal. The optimal route is 2,3,4,6,4,5,4,3,1ドル$ instead (also marked in red in the picture).
Notice in Sample Case #3 that the answer may be larger than 2ドル^{32}$.
Contest > Google > Code Jam to I/O for Women > Code Jam to I/O for Women 2022 > Code Jam to I/O for Women 2022 C번