PivotOJ

Family Fares

시간 제한: 3000ms메모리 제한: 512MB출처: UKIEPC 2020BOJ 20334

문제

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.

Figure F.1: Sample 2. Group or individual tickets are shown by thick or thin lines, respectively.

입력

  • One line with four integers: nn (2n10002 \le n \le 1000), the number of stations, mm (n1m105n-1 \le m \le 10^5), the number of connections between stations, pp (1p1001 \le p \le 100), the number of family members, and gg (1g1061 \le g \le 10^6), the cost per person of a group ticket.
  • One line with pp integers viv_i (1vn1 \le v \le n), meaning that family member ii starts at station viv_i.
  • mm further lines, each with three integers aa, bb, and cc (1a,bn{1 \le a,b \le n}, aba\neq b, and 1c106{1 \le c \le 10^6}), indicating that 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 number 11 serves the idyllic village.

출력

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

예제

예제 1

입력
6 5 3 10
4 5 6
1 2 10
2 3 10
3 4 10
4 5 2
4 6 3
출력
35

예제 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

예제 3

입력
4 5 2 10
2 4
1 2 20
2 4 5
1 3 20
3 4 5
1 4 30
출력
25
코드를 제출하려면 로그인하세요.