Under construction

Still being built. Things may change

Interesting Outing

Interview

Time limit10sMemory limit1024 MB

Summary
Given a weighted tree, find the minimum total edge cost of a walk that visits every node, starting and ending at any nodes.
Level

Medium4 of 10

Topics
Tree, DFS, Dynamic programming
Solved
No attempts yet

Problem

You are hosting visitors from out of town and want to take them out to see the most interesting places in town.

There are NN interesting sights you want to tour. You have identified N−1N-1 interesting methods of transportation. Each method connects a pair of sights in both directions. There is exactly one way to get from any sight to any other without using any transportation method more than once.

You know the cost for the group to use each transportation method one time (you pay once per use). You choose the starting and ending sights, which can be the same or different. You do not count the cost of getting to the starting sight or coming back from the ending sight, only the transportation cost during the tour. What is the cheapest way to see all sights at least once each?

Input

The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case starts with a line containing a single integer NN, the number of sights. Then, N−1N-1 lines follow. The ii-th of these lines contains three integers AiA_i, BiB_i, and CiC_i, meaning the ii-th transportation method connects sight AiA_i and sight BiB_i in both directions at a cost of CiC_i coins per usage.

Output

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

Constraints

1≤T≤1001≤T≤100.

1≤Ai<Bi≤N1≤A_i<B_i≤N, for all ii.

It is possible to travel between any pair of sights using only the given transportation methods. (This and the previous limit imply the sights and transportation methods form an unrooted tree.)

1≤Ci≤1091≤C_i≤10^9 for all ii.

Hint

In Sample Case #1 (see the picture), an optimal route, marked with a red line, visits sights 2,3,1,3,4,5,4,62,3,1,3,4,5,4,6.

In Sample Case #2, the only change from Sample Case #1 is that the transportation between sights 11 and 33 got more expensive, rising from 1010 to 3535. The route 2,3,1,3,4,5,4,62,3,1,3,4,5,4,6 now costs 150150 and 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.

In Sample Case #3, note that the answer may be larger than 2322^{32}.

Examples1

  1. Example 1

    Input
    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
    
    Expected output
    Case #1: 100
    Case #2: 145
    Case #3: 6000000000