LCC '25 Contest 3 S3 - Present Conveyor System
View as PDFNow that all the presents are wrapped, Santa must transport and load all the presents onto his sled. There are stations in the North Pole numbered
to
, and stations are connected by
conveyor belts. Each conveyor belt travels bidirectionally and connects exactly two stations, however, the conveyor belts do not necessarily move at the same speed. There are
wrapping stations, and
loading stations. All presents must pass through one of the
packaging stations, where the presents are labelled and packaged into sacks. Santa wants to know the minimum amount of time it takes for a present from any of the
wrapping stations to arrive at any of the
loading stations, while passing through one of the
packaging stations.
Input Specification
The first line contains .
The next lines each contain 3 integers
, meaning it takes
seconds to move presents from station
to station
.
The next line contains integers, denoting the wrapping stations.
The next line contains integers, denoting the packaging stations.
The next line contains integers, denoting the loading stations.
Note that the purpose of each station is unique. So, for example, a station cannot be both a packaging station and a loading station. However, a station can have no purpose.
Output Specification
Output the minimum amount of time for any present to go from a wrapping station to a packaging station to a loading station.
Constraints
For all subtasks:
Subtask 1 [30%]
Subtask 2 [70%]
Sample Input 1
7 10 2 1 2
1 6 10
2 4 5
7 4 23
3 2 5
4 5 7
3 1 18
6 7 9
5 2 1
4 1 3
5 3 2
1 4
3
2 7
Output for Sample Input 1
11
Explanation of Output for Sample Input 1
The fastest way is to start at wrapping station and end at loading station
through the path:
This takes
seconds. Note that the path
is not valid, as it does not pass through, in this case the only packaging station,
.
Sample Input 2
9 14 2 2 3
1 2 8
2 3 12
3 4 7
4 5 5
5 6 10
6 7 6
7 8 9
8 9 10
1 5 15
2 6 11
3 7 8
4 8 13
5 9 6
1 7 20
1 9
5 4
2 8 7
Output for Sample Input 2
22
Comments