Logo
(追記) (追記ここまで)

24921번 - Interesting Outing 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
10 초 (추가 시간 없음) 1024 MB (추가 메모리 없음)26161560.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.

제한

  • 1ドル≤T≤100$.
  • 1ドル≤A_i<B_i≤N,ドル for all $i$.
  • 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.)
  • 1ドル≤C_i≤10^9$ for all $i$.

Test Set 1 (9점)

  • 2ドル≤N≤10$.

Test Set 2 (15점)

  • 2ドル≤N≤1000$.

예제 입력 1

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

예제 출력 1

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번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /