Under construction

Still being built. Things may change

Relay Marathon

Time limit6sMemory limit512 MB

Summary
Given a weighted undirected graph and K special cities, find two pairs of distinct special cities, all four different, whose shortest-path distances sum to the minimum.
Level

Medium7 of 10

Topics
Graph, Shortest path, Heap
Solved
No attempts yet

Problem

You are Nilan, the marathon organiser of the country Berapur. There are N cities in the country, connected by M roads. The cities are indexed from 1 to N, and each road is indexed from 1 to M. The ith road connects city u_i directly with city v_i, and it takes w_i seconds to travel on it. Roads are bidirectional. There are no self-loops or multi-edges. Among the N cities, there is a list of K distinct cities A_1, A_2, ..., A_K that are special.

A relay marathon works as follows. Two groups of people start at the cities start1 and start2. First, the group at start1 travels to finish1. As soon as the first group reaches finish1, the second group starts traveling from start2 to finish2 with no delay. When the second group reaches finish2, the relay ends. A relay is valid only if start1, finish1, start2, and finish2 are all special and distinct from one another.

Let D(a, b) be the length of the shortest path from city a to city b. If no path exists, D(a, b) = ∞\infty. The total time of a valid relay is D(start1, finish1) + D(start2, finish2). Find the minimum total time over all valid tuples (start1, finish1, start2, finish2).

It is guaranteed that at least one valid tuple of four distinct special cities (a, b, c, d) exists with D(a, b) + D(c, d) < ∞\infty.

Input

The first line contains three integers N, M, and K. Each of the next M lines contains three integers u_i, v_i, and w_i, meaning a road joins cities u_i and v_i and takes w_i seconds in either direction. The last line contains the K distinct integers A_1, A_2, ..., A_K, the special cities.

Output

Print a single integer on one line: the minimum value of D(start1, finish1) + D(start2, finish2) (in seconds).

Constraints

4≤K≤N≤1054 \le K \le N \le 10^5

2≤M≤min⁡(N(N−1)/2,3×106)2 \le M \le \min(N(N-1)/2, 3 \times 10^6)

1≤wi≤10001 \le w_i \le 1000 for all 1≤i≤M1 \le i \le M

1≤ui≠vi≤N1 \le u_i \ne v_i \le N for all 1≤i≤M1 \le i \le M

Examples2

  1. Example 1

    Input
    5 4 4
    1 2 1
    3 4 2
    4 5 5
    5 3 8
    3 1 5 2
    
    Expected output
    8
    
  2. Example 2

    Input
    6 6 4
    1 2 5
    2 4 7
    4 6 50
    6 5 3
    1 5 15
    3 5 6
    1 5 4 6
    
    Expected output
    15