Under construction

Still being built. Things may change

Family Fares

Time limit3sMemory limit512 MB

Summary
Find the minimum total cost for each family member to reach station 1, choosing shortest-path individual tickets or one group ticket priced at g per person.
Level

Medium6 of 10

Topics
Shortest path, Graph, Dynamic programming
Solved
No attempts yet

Problem

After a long time apart, your family will gather next year at an idyllic village in the centre of the country. Everyone lives apart, so most will travel by train.

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

Two types of ticket are available: individual and group. Every ticket has a start and a destination. Individual tickets are unlimited, and the price equals the shortest distance in kilometres between the two stations.

Group tickets are more complicated. You may buy at most one, and it must be for a fixed list of people. There is no limit to the number of people named, but all of them must be present. The price depends on the number of named persons.

Thick lines are group tickets, and thin lines are individual tickets.

Input

The first line has four integers: nn (2≤n≤10002 \le n \le 1000), the number of stations, mm (n−1≤m≤105n-1 \le m \le 10^5), the number of connections, pp (1≤p≤1001 \le p \le 100), the number of family members, and gg (1≤g≤1061 \le g \le 10^6), the cost per person of a group ticket.

The second line has pp integers viv_i (1≤v≤n1 \le v \le n), meaning family member ii starts at station viv_i.

Each of the next mm lines has three integers aa, bb, and cc (1≤a,b≤n1 \le a,b \le n, a≠ba \neq b, and 1≤c≤1061 \le c \le 10^6), meaning there is a bidirectional connection between stations aa and bb with a length of cc kilometres.

Each pair of distinct stations has at most one direct connection, and every station can be reached from any other station. Station 11 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.

Examples3

  1. Example 1

    Input
    6 5 3 10
    4 5 6
    1 2 10
    2 3 10
    3 4 10
    4 5 2
    4 6 3
    
    Expected output
    35
    
  2. Example 2

    Input
    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
    
    Expected output
    145
    
  3. Example 3

    Input
    4 5 2 10
    2 4
    1 2 20
    2 4 5
    1 3 20
    3 4 5
    1 4 30
    
    Expected output
    25