#P2469. [SDOI2010] 星际竞速

    ID: 1480 远端评测题 2000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2010各省省选网络流山东最大流费用流

[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 α\alpha star is one of them.

The racecourse consists of NN planets and MM 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 NN planets, visit each of the NN 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 N,MN, M.

The second line contains NN integers A1,,ANA_1,\cdots,A_N, where AiA_i is the positioning time required to reach planet ii using Ability Burst mode.

Each of the next MM lines contains three positive integers ui,vi,wiu_i, v_i, w_i, indicating that there is a bidirectional interstellar route between planets uiu_i and viv_i that takes wiw_i 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 11, costing time 11.

Then switch to High-Speed Sailing mode and travel to planet 22, costing time 1010.

After that, continue to planet 33 to finish the race, costing time 11.

Although going from planet 11 to 33 and then to 22 seems better, we cannot do that because it would cause the Super E-Donkey to explode.

Constraints

  • For 30%30\% of the testdata, N20N \leq 20, M50M \leq 50.
  • For 70%70\% of the testdata, N200N \leq 200, M4×103M \leq 4 \times 10^3.
  • For 100%100\% of the testdata, N800N \leq 800, M1.5×104M \leq 1.5 \times 10^4.
  • Every number in the input is between 11 and 10610^6.
  • There is at most one route between any pair of planets, and there are no self-loops.

Translated by ChatGPT 5