The Crocodile's Underground City

Time limit2sMemory limit256 MB

Summary
Find the minimum guaranteed escape time from room 0 to any exit room when a gatekeeper blocks one corridor at each room before Chulsoo moves.
Level

Hard8 of 10

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

Problem

Archaeologist Chulsoo was exploring a mysterious underground city of crocodiles when he sensed danger and had to flee.

The underground city has NN rooms, numbered 00 to N−1N-1. There are MM corridors, each connecting two distinct rooms, and each corridor takes a certain amount of time to traverse. At most one corridor connects any given pair of rooms. Among the NN rooms, KK are exit rooms from which one can escape immediately. Chulsoo starts in room 00 (which is not an exit room) and wants to reach any exit room as fast as possible.

The crocodile gatekeeper tries to stop Chulsoo. At any single moment the gatekeeper may block exactly one corridor; blocking a new corridor reopens the previously blocked one. Concretely, when Chulsoo is about to leave a room, the gatekeeper may block one of the corridors attached to that room. Chulsoo then chooses one of the unblocked corridors and moves. Once Chulsoo has entered a corridor, it cannot be blocked until he finishes crossing it. After he arrives in another room, the gatekeeper may again block one corridor (including the one he just used), and so on.

Chulsoo fixes an escape plan in advance, specifying what to do upon reaching each room. If room AA is an exit room, he escapes immediately and needs no plan. Otherwise, the plan for room AA must be one of:

  • From room AA, first move to room BB; if that corridor is blocked, move to room CC instead.
  • Room AA is never reached under this plan, so no action is specified.

Note that under some plans (for example, if Chulsoo walks in a cycle) the gatekeeper can make escape impossible forever. A plan is called good if it guarantees that, no matter what the gatekeeper does, Chulsoo escapes in finite time. For a good plan, the smallest time TT such that Chulsoo is guaranteed to have escaped after TT regardless of the gatekeeper's strategy is called the plan's escape time.

The input describes the following values.

  • NN — the number of rooms, numbered 00 to N−1N-1.
  • MM — the number of corridors, numbered 00 to M−1M-1.
  • Each corridor ii (0≤i<M0 \le i < M) connects room R[i][0] and room R[i][1], and takes L[i] (1≤L[i]≤1091 \le L[i] \le 10^9) time to traverse. At most one corridor connects any pair of rooms.
  • KK — the number of exit rooms (1≤K<N1 \le K < N).
  • P[0], …, P[K-1] — the exit room numbers. They are all distinct, and room 00 is not among them.

Output the minimum escape time TT over all good plans. You may assume every non-exit room has at least 22 corridors attached, and that every input admits a good plan with T≤109T \le 10^9.

Input

The first line contains NN, MM, and KK. Each of the next MM lines contains R[i][0], R[i][1], and L[i] for one corridor. Each of the following KK lines contains one exit room number P[i].

Output

Print the minimum escape time TT on a single line.

Examples2

  1. Example 1

    Input
    5 4 3
    0 1 2
    0 2 3
    3 2 1
    2 4 4
    1
    3
    4
    
    Expected output
    7
    
  2. Example 2

    Input
    5 7 2
    0 2 4
    0 3 3
    3 2 2
    2 1 10
    0 1 100
    0 4 7
    3 4 9
    1
    3
    
    Expected output
    14