#P2469. [SDOI2010] 星际竞速
[SDOI2010] 星际竞速
Description
The once-in-a-decade Milky Way Grand Prix is about to begin. As one of the biggest events in the galaxy, winning this championship is undoubtedly the dream of many. Youyou from the Jason constellation’s star is one of them.
The racecourse consists of planets and bidirectional interstellar routes. Each planet has a distinct gravity value. The race requires drivers to start from a celestial body that has no interstellar route to any of these planets, visit each of the planets exactly once, and the first to achieve this wins.
Thanks to the very open rules, many contestants drive all sorts of homemade vehicles. This time, Youyou is driving a car named “Super E-Donkey,” a dream machine embodying the most cutting-edge technology in the galaxy. As a pinnacle of technology, the Super E-Donkey has two movement modes: High-Speed Sailing mode and Ability Burst mode. In High-Speed Sailing mode, it deploys an antimatter engine to speed along interstellar routes at many times the speed of light. In Ability Burst mode, it breaks free from the constraints of spacetime and uses psychic power for spatial jumps—after a period of positioning, it can instantly teleport to any planet.
Unfortunately, on the day before the race, the Super E-Donkey was damaged in an ion storm, causing some malfunctions: when using High-Speed Sailing mode, it can only fly from any planet to a planet with strictly greater gravity; otherwise, the car will explode.
Even though his beloved car has issues, Youyou still believes he can win. He has found the wisest sage in the galaxy—you. Please plan a racing scheme for him so that he can finish the race in the minimum possible time.
Input Format
The first line contains two positive integers .
The second line contains integers , where is the positioning time required to reach planet using Ability Burst mode.
Each of the next lines contains three positive integers , indicating that there is a bidirectional interstellar route between planets and that takes time to traverse.
The input is already sorted by gravity, meaning that a smaller-indexed planet has smaller gravity, and no two planets have the same gravity.
Output Format
Output a single integer: the minimum time required to finish the race.
3 3
1 100 100
2 1 10
1 3 1
2 3 1
12
3 3
1 2 3
1 2 100
1 3 100
2 3 100
6
4 5
100 1000 10 100
1 2 100
2 3 100
4 3 100
1 3 20
2 4 20
230
Hint
Explanation for Sample 1: First use Ability Burst mode to reach planet , costing time .
Then switch to High-Speed Sailing mode and travel to planet , costing time .
After that, continue to planet to finish the race, costing time .
Although going from planet to and then to seems better, we cannot do that because it would cause the Super E-Donkey to explode.
Constraints
- For of the testdata, , .
- For of the testdata, , .
- For of the testdata, , .
- Every number in the input is between and .
- There is at most one route between any pair of planets, and there are no self-loops.
Translated by ChatGPT 5
京公网安备 11011102002149号