Hide

Problem D
Family Fares

After a long time apart, your family will gather next year for a reunion in an idyllic village in the centre of the country. Since everybody lives apart, most will need to travel by train.

You are in charge of finding the best deal on tickets. Everyone must take an optimal route, that is to say they may only travel a route if no other route is shorter.

Two types of ticket are available: individual or group. All tickets come with a start and destination between which to travel. Individual tickets are unlimited and the price is equal to the shortest distance in kilometres between stations.

Group tickets are more complicated. First, you may only buy at most one and it must be for a set list of people. There is no limit to the number of people named, but all must be present. The ticket is priced according to the number of named persons.

\includegraphics[width=0.5\textwidth ]{figure}
Figure 1: Sample 2. Group or individual tickets are shown by thick or thin lines, respectively.

Input

  • One line with four integers: $n$ ($2 \le n \le 1000$), the number of stations, $m$ ($n-1 \le m \le 10^5$), the number of connections between stations, $p$ ($1 \le p \le 100$), the number of family members, and $g$ ($1 \le g \le 10^6$), the cost per person of a group ticket.

  • One line with $p$ integers $v_ i$ ($1 \le v \le n$), meaning that family member $i$ starts at station $v_ i$.

  • $m$ further lines, each with three integers $a$, $b$, and $c$ (${1 \le a,b \le n}$, $a\neq b$, and ${1 \le c \le 10^6}$), indicating that there is a bidirectional connection between stations $a$ and $b$ with a length of $c$ kilometres.

Each pair of distinct stations has at most one direct connection and every station can be reached from any other station. Station number $1$ serves the idyllic village.

Output

Output the total amount you must spend so that every family member can travel from their starting station to the idyllic village.

Sample Input 1 Sample Output 1
6 5 3 10
4 5 6
1 2 10
2 3 10
3 4 10
4 5 2
4 6 3
35
Sample Input 2 Sample Output 2
7 7 4 10
5 4 4 7
1 2 100
2 3 100
3 4 10
1 5 80
3 5 30
3 6 10
6 7 5
145
Sample Input 3 Sample Output 3
4 5 2 10
2 4
1 2 20
2 4 5
1 3 20
3 4 5
1 4 30
25

Please log in to submit a solution to this problem

Log in