#P16146. [ICPC 2017 NAIPC] Blazing New Trails

[ICPC 2017 NAIPC] Blazing New Trails

题目描述

Your state has just purchased a large, unspoiled tract of land, and wishes to turn it into a nature park with hiking trails. The land has nn places of interest to which guests may wish to hike, and of these, kk are very special. The state wishes to connect these places with hiking trails. There are mm candidate hiking trails to choose from that directly connect two places of interest with various costs. There are some constraints for choosing the trails. First, there must be exactly one way to hike from any place to any other place. Second, exactly ww of the trails must directly connect a special place with a regular place. Of course, the state wishes to minimize the cost of blazing these trails.

输入格式

Each input will consist of a single test case. Note that your program may be run multiple times on different inputs. The first line of input will contain four integers nn, mm, kk and ww, where nn (2n21052 \leq n \leq 2 \cdot 10^5) is the number of places, mm (1m51051 \leq m \leq 5 \cdot 10^5) is the number of potential direct trails between places, kk (1k<n1 \leq k < n) is the number of special places, and ww (1wn11 \leq w \leq n - 1) is the number of special-nonspecial direct trails the state wishes to blaze. The places are numbered 1..n1..n.

Each of the next kk lines holds a single integer ss (1sn1 \leq s \leq n) indicating the special places. These values will be unique and will be in ascending order.

Each of the next mm lines will describe a potential trail that the state could blaze. Each of these lines will consist of three integers, aa, bb and cc, where the trail would go between places aa and bb (1a,bn,ab1 \leq a, b \leq n, a \neq b) and would cost cc (1c1051 \leq c \leq 10^5). No two places will have more than one potential trail between them, and a trail from aa to bb is the same as a trail from bb to aa.

输出格式

Output a single integer, which is the minimum total cost for the state to blaze trails in their new park subject to their constraints, or 1-1 if it isn’t possible.

3 3 1 2
2
1 2 2
1 3 1
2 3 3
5
3 1 1 1
2
1 2 2
-1