HDU1863- Smooth Traffic Project

Target provincial government "Smooth Traffic Project" is to make between any two villages in the province can achieve road traffic (but not necessarily directly connected to the road, as long as indirectly through the road up to). After investigation and assessment, statistics obtained a list of possible construction of several roads highway costs. Now you write a program to calculate the lowest cost needed to clear the province.

Input test input contains several test cases. The first row of each road test strip evaluation given number N, the number of villages M (<100); N subsequent
cost of correspondence between the village road rows each given a pair of positive integers, respectively, two villages the number and cost of road between these two villages (and a positive integer). For simplicity, the village numbered from 1 to M. When N is 0, all the input end, an output not corresponding results.
Output For each test case, output the lowest cost needed to clear the province in a row. If the data is not sufficient to ensure the smooth flow statistics, output "?."
Sample Input

3 3
1 2 1
1 3 2
2 3 4
1 3
2 3 2
0 100

Sample Output

3
?

Guess you like

Origin www.cnblogs.com/OFSHK/p/11853596.html