#P7192. [COCI 2007/2008 #6] GEORGE
[COCI 2007/2008 #6] GEORGE
Background
Mr. T came to visit Luka’s small town. Because Mr. T is an important person, the police will impose traffic control on the roads he will pass through.
Luka is a delivery truck driver in the town. However, because some roads are under traffic control, he cannot deliver on time and almost lost his job.
Problem Description
Luka knows Mr. T’s travel route, and he wants to know the shortest delivery time.
The city consists of several intersections connected by roads, and Luka knows how long it takes to drive through each road segment (Mr. T needs the same amount of time to drive through that segment).
For example, if Mr. T enters a road at minute and needs minutes to leave the road, then this street will be closed during minutes . Luka can enter this road at minute or earlier, or at minute or later.
Write a program to compute the minimum time Luka needs to drive, assuming Luka starts driving minutes after Mr. T arrives in the city.
Input Format
The first line contains two positive integers , representing the number of intersections and the number of streets. Intersections are numbered from to .
The second line contains four positive integers , where:
- : the intersection where Luka starts.
- : the intersection Luka must reach.
- : the difference between Mr. T’s departure time and Luka’s departure time.
- : the number of intersections on Mr. T’s route.
The third line contains integers, representing the intersections on Mr. T’s route in order. It is guaranteed that the corresponding streets exist, and each street is used at most once.
The next lines each contain three integers , meaning there is a street between intersections and , and the travel time along it is .
Output Format
Output one line containing the minimum time (in minutes) Luka needs to complete the delivery.
6 5
1 6 20 4
5 3 2 4
1 2 2
2 3 8
2 4 3
3 6 10
3 5 15
21
8 9
1 5 5 5
1 2 3 4 5
1 2 8
2 7 4
2 3 10
6 7 40
3 6 5
6 8 3
4 8 4
4 5 5
3 4 23
40
Hint
Constraints
For of the testdata, , , , , .
Notes
- The full score for this problem is points.
- This problem enables the O2 optimization switch by default.
- Translated from COCI2007-2008 CONTEST #6 T4 GEORGE, translator: https://www.luogu.com.cn/user/219791
Translated by ChatGPT 5