LCC '25 Contest 3 S3 - Present Conveyor System

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

Now that all the presents are wrapped, Santa must transport and load all the presents onto his sled. There are N stations in the North Pole numbered 1 to N, and stations are connected by M 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 W wrapping stations, and L loading stations. All presents must pass through one of the P 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 W wrapping stations to arrive at any of the L loading stations, while passing through one of the P packaging stations.

Input Specification

The first line contains N,M,W,P,L.

The next M lines each contain 3 integers u,v,t, meaning it takes t seconds to move presents from station u to station v.

The next line contains W integers, denoting the wrapping stations.

The next line contains P integers, denoting the packaging stations.

The next line contains L 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:

  • t\leq 500
  • W,P,L\leq N
Subtask 1 [30%]

3\leq N,M\leq 100

Subtask 2 [70%]

3\leq N,M \leq 2\cdot 10^5

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 4 and end at loading station 2 through the path: 4 \rightarrow 2 \rightarrow 5\rightarrow 3\rightarrow 5\rightarrow 2. This takes 5+1+2+2+1=11 seconds. Note that the path 4\rightarrow 2 is not valid, as it does not pass through, in this case the only packaging station, 3.

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

There are no comments at the moment.