Under construction

Still being built. Things may change

Explorace

Time limit3sMemory limit512 MB

Summary
Given a weighted undirected graph of checkpoints, find the minimum total length of edges that keeps every checkpoint connected.
Level

Easy3 of 10

Topics
Minimum spanning tree, Graph, Greedy, Union-find
Solved
No attempts yet

Problem

An explorace is held to welcome new students. Each team must visit every checkpoint in any order it chooses, completing a designated activity at each checkpoint.

To keep newcomers from wandering off, the organizers place staff members on some paths and allow students to use only staffed paths. Staff are limited, so the organizers want to minimize the total length of the staffed paths while still guaranteeing that every pair of checkpoints is connected by some route. Each path connects checkpoints aa and bb in both directions with length dd, and every path length is at most 500500. For each test case, find the minimum possible total length of the paths that must be staffed.

Input

The first line gives the number of test cases TT (1≤T≤101 \le T \le 10). The first line of each test case gives the number of checkpoints NN and the number of candidate paths MM (1≤N≤201 \le N \le 20, 1≤M≤N(N−1)1 \le M \le N(N-1)). Each of the following MM lines gives three integers aa, bb and dd (1≤a,b≤N1 \le a, b \le N, 1≤d≤5001 \le d \le 500), meaning there is a path of length dd connecting checkpoint aa and checkpoint bb.

Output

For each test case, print one line in the form Case #x: y meters, where xx is the 1-based test case number and yy is the minimum total length of the paths to staff.

Examples1

  1. Example 1

    Input
    3
    5 7
    1 2 75
    2 3 32
    3 4 62
    1 4 50
    3 5 100
    4 5 45
    1 5 78
    6 8
    1 2 70
    1 4 82
    2 3 57
    2 5 105
    3 4 160
    3 6 55
    4 5 97
    4 6 75
    4 5
    1 2 10
    1 3 30
    1 4 40
    2 3 20
    3 4 50
    
    Expected output
    Case #1: 189 meters
    Case #2: 354 meters
    Case #3: 70 meters