#P7669. [JOI 2018 Final] 月票购买 / Commuter Pass
[JOI 2018 Final] 月票购买 / Commuter Pass
Description
JOI lives in a city with stations, numbered from to . There are railways, numbered from to . Railway () connects stations and in both directions, and its fare is yen.
JOI lives near station and goes to IOI High School near station . He plans to buy a commuter pass connecting these two stations. When buying the commuter pass, he must choose a route of minimum total cost between station and station . With this commuter pass, he can ride any railway included in the chosen route in either direction without any additional cost.
JOI often visits a bookstore near stations and . Therefore, he wants to buy a commuter pass so that the cost of traveling from station to station is minimized.
When he travels from station to station , he first chooses a route from station to station . Then the fare he needs to pay is:
- yen if railway is included in the route chosen when buying the commuter pass, or
- yen if railway is not included in the route chosen when buying the commuter pass.
The total of these fares is the cost from station to station .
He wants to know the minimum possible cost from station to station if he chooses an appropriate route when buying the commuter pass.
Input Format
The first line contains two space-separated integers and , meaning the city has stations and railways.
The second line contains two space-separated integers and , meaning JOI plans to buy a commuter pass from station to station .
The third line contains two space-separated integers and , meaning JOI wants to minimize the cost from station to station .
Each of the next lines, the -th line contains three space-separated integers , , and . Railway connects stations and in both directions, and its fare is yen.
Output Format
Output one integer: the minimum cost from station to station if he chooses an appropriate route when buying the commuter pass.
6 6
1 6
1 4
1 2 1
2 3 1
3 5 1
2 4 3
4 5 2
5 6 1
2
6 5
1 2
3 6
1 2 1000000000
2 3 1000000000
3 4 1000000000
4 5 1000000000
5 6 1000000000
3000000000
8 8
5 7
6 8
1 2 2
2 3 3
3 4 4
1 4 1
1 5 5
2 6 6
3 7 7
4 8 8
15
5 5
1 5
2 3
1 2 1
2 3 10
2 4 10
3 5 10
4 5 10
0
10 15
6 8
7 9
2 7 12
8 10 17
1 3 1
3 8 14
5 7 15
2 3 7
1 10 14
3 6 12
1 5 10
8 9 1
2 9 7
1 4 1
1 8 1
2 4 7
5 6 16
19
Hint
Constraints
For of the testdata: , , , , , , , , or , (). For every , or , (). JOI can travel from any station to any other station by railways.
- Subtask ( points): .
- Subtask ( points): There is a unique minimum-cost route from station to station .
- Subtask ( points): .
- Subtask ( points): No additional constraints.
Sample Explanation
For Sample 1: When buying the commuter pass, JOI can choose only one route: station → station → station → station → station . To minimize the cost from station to station , he chooses the route: station → station → station → station → station . For this route, the fares he needs to pay are:
- yen for railway between station and station , and
- yen for all other railways.
For Sample 2: When JOI travels from station to station , he does not use the commuter pass.
Problem Source
From The 17th Japanese Olympiad in Informatics (JOI 2017/2018) Final Round, T4: Commuter Pass.
Translated and整理 (pinyin: zhengli, compiled) by @求学的企鹅.
Hack Notes
@gaojunqing provided a set of hack data to the problem setter on November 6, 2021. After multiple checks, it was added to this problem’s testdata on November 7, 2021.
To respect the original JOI problem and its intended experience, all added hack data does not change the scoring: the full score is still 100 points. The new hack data is placed separately in Subtask #5 with a score of 0 points. That is, if you pass all original testdata but fail the hack data, you will get 100 points but will not be accepted (AC). You will be accepted (AC) only if you pass all testdata.
Translated by ChatGPT 5
京公网安备 11011102002149号