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
places of interest to which guests may wish to hike, and of
these, are very
special. The state wishes to connect these places with hiking
trails. There are
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 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.
Input
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 , , and , where () is the number of places,
() is the
number of potential direct trails between places, () is the number of special places, and
() is the number of
special-nonspecial direct trails the state wishes to blaze. The
places are numbered to
.
Each of the next
lines holds a single integer () indicating the special places. These
values will be unique and will be in ascending order.
Each of the next
lines will describe a potential trail that the state could
blaze. Each of these lines will consist of three integers,
, and , where the trail would go between
places and
() and would
cost (). No two places
will have more than one potential trail between them, and a
trail from to
is the same as a trail
from to .
Output
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 if it
isn’t possible.
Sample Input 1 |
Sample Output 1 |
3 3 1 2
2
1 2 2
1 3 1
2 3 3
|
5
|
Sample Input 2 |
Sample Output 2 |
3 1 1 1
2
1 2 2
|
-1
|