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 NN interesting sights you want to tour. You have identified N1N-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, TTTT test cases follow. Each test case starts with a line containing a single integer NN, the number of sights you want to tour. Then, N1N-1 lines follow. The ii-th of these lines contains three integers A_iA\_iB_iB\_i, and C_iC\_i, representing that the ii-th method of transportation can take your group from sight A_iA\_i to sight B_iB\_i or from sight B_iB\_i to sight A_iA\_i for a cost of C_iC\_i coins per usage.

출력

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is an integer representing the minimum cost of a tour that visits each sight at least once.

제한

  • 1T1001≤T≤100.
  • 1A_i\<B_iN1≤A\_i\<B\_i≤N, for all ii.
  • 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.)
  • 1C_i1091≤C\_i≤10^9 for all ii.

힌트

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,62,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 11 and 33 got more expensive: from 1010 to 3535. The route 2,3,1,3,4,5,4,62,3,1,3,4,5,4,6 costs 150150 in this scenario and it is not optimal. The optimal route is 2,3,4,6,4,5,4,3,12,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 2322^{32}.