Explorace
Time limit3sMemory limit512 MB
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 and in both directions with length , and every path length is at most . 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 (). The first line of each test case gives the number of checkpoints and the number of candidate paths (, ). Each of the following lines gives three integers , and (, ), meaning there is a path of length connecting checkpoint and checkpoint .
Output
For each test case, print one line in the form Case #x: y meters, where is the 1-based test case number and is the minimum total length of the paths to staff.