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 () locations.
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 possible routes to travel. (However, it's still guaranteed he'll be able to deliver everything)
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
(number of locations, ).
lines, each with three integers .
Each line represents a route between locations and , that takes seconds to traverse.
(Location is the North Pole)
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 ( second), back to the North Pole ( second), and finally to location ( second).
Comments
Since the original data were weak, an additional test case was added, and all submissions were rejudged.