#P3406. 海底高铁
海底高铁
Description
The railway passes through cities, each of which has a station. However, because the cities could not coordinate, each time you travel between two adjacent cities (in either direction), you must buy a separate ticket for that segment. Segment connects city and city (). If you travel farther, you need to buy multiple tickets. A paper one-way ticket for segment costs Boai yuan.
Although coordination fell short, the companies of each segment introduced IC cards for convenience. For segment , you can pay a fee of Boai yuan to purchase an IC card, after which each ride on this segment only deducts () yuan. IC cards can be purchased online in advance; you do not need to buy them in the corresponding city. The card fee is non-refundable and cannot be used to buy tickets. Each card can be topped up with any amount. An IC card for segment cannot be used on other segments.
Uim needs to go on a business trip to visit cities, starting from city and visiting cities in the order . A city may be visited multiple times; consecutive cities in the sequence are not necessarily adjacent on the line, and they are guaranteed to be different.
Now he wants to know, after the trip ends, what is the minimum amount of money he will spend in total, including the cost of paper tickets, buying IC cards, and the rides paid with IC cards.
Input Format
- The first line contains two integers, .
- The next line contains integers, representing .
- The next lines describe the segments: for segment , three integers .
Output Format
Output a single integer, the minimum total cost.
9 10
3 1 4 1 5 9 2 6 5 3
200 100 50
300 299 100
500 200 500
345 234 123
100 50 100
600 100 1
450 400 80
2 1 10
6394
Hint
- Buy paper tickets for to and to , and buy IC cards for the others.
Constraints:
- For of the testdata, .
- For another of the testdata, , .
- For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号