Now that Santa's put all the presents in his magic bag, he's going to go deliver the presents!
Of course, he's going to fly in the sky with the help of his trusty reindeer.
(How he delivers everything in time is another story…)
Santa starts at the North Pole, and must visit several (
But he can't just travel however he wants.
Terrorists might try hunting him, or he might get shot down in protected airspace…
Also, some routes are really slow because of air currents.
Thus Santa has exactly
The routes are all two-way.
Given a list of these routes, output the time it takes for Santa to deliver the presents to every location!
Santa can visit places in any order, though.
Input Specification
Each line represents a route between locations
(Location
Output Specification
The minimum time it takes to deliver presents everywhere.
He won't have to return to the North Pole.
Sample Input
2
0 1 1
0 2 1
Sample Output
3
Santa goes from the North Pole to location
Comments
Since the original data were weak, an additional test case was added, and all submissions were rejudged.