Evacuation

면접 대비

시간 제한1초메모리 제한2048 MB

요약
무방향 가중 그래프에서 토네이도가 주어진 경로를 따라 이동하며 도착하는 다리를 파괴할 때, H에서 E로 이동하는 최단 시간을 구한다.
난이도

보통10점 중 7점

유형
그래프, 최단 경로, 그리디
정답자
아직 제출이 없습니다

문제

A city specified by a set of districts and bridges is under threat. Initially, each district can reach any other district through some series of bridges.

A tornado has touched down at district D_1D\_1 and is destroying everything in its way. The latest model suggests the tornado will destroy districts D_1,…,D_KD\_1,\dots ,D\_K following the bridges between (D_i,D_i+1)(D\_i,D\_{i+1}). Upon reaching district D_KD\_K the model is not accurate enough to precisely determine the tornadoes course.

Given the tornadoes predicted course you must determine the minimum time it would take to travel from your home located in district HH to the evacuation shelter located in district EE. Of course, once the tornado begins travelling down a bridge it becomes unstable disallowing its use; that is, if the tornado arrives at D_iD\_i at time T_iT\_i and is heading towards D_jD\_j, the bidirectional bridge (D_i,D_j)(D\_i,D\_j) will no longer be safe to use at any time T≥T_iT≥T\_i, even if you would nearly be finished crossing it.

Due to their size, residing in the same district as the tornado poses no threat.

입력

The first line of input will contain three integers, NN, MM, KK, indicating there are 2≤N≤1042≤N≤10^4 districts, N−1≤M≤min⁡(105,N(N+1)2N-1≤M≤\min(10^5,\frac{N(N+1)}{2}) bridges, and the tornadoes predicted course contains 2≤K≤N2≤K≤N districts.

The next line of input contains two integers 1≤H,E≤N1≤H,E≤N indicating the district of your home and the evacuation shelter respectively.

The following MM lines contain three integers each, U_iU\_i, V_iV\_i, T_iT\_i, indicating there is a bidirectional bridge between districts 1≤U_i≤N1≤U\_i≤N and 1≤V_i≤N1≤V\_i≤N that takes 1≤T_i≤1001≤T\_i≤100 time to cross. There will be at most one bridge between any pair of districts and U_i≠V_iU\_i \ne V\_i for each bridge.

The final line contains KK space separated integers indicating the districts which the tornado is predicted to destroy. All bridges the tornado follows are guaranteed to exist, the tornado crosses each bridge in the same amount of time it would take for you to cross.

출력

Output a single integer indicating the minimum amount of time it will take to reach district EE from district HH while avoiding all unstable bridges. Output −1-1 if it is impossible to reach EE from HH.

예제3

  1. 예제 1

    입력
    4 3 4
    2 4
    1 2 1
    2 3 1
    3 4 1
    1 2 3 4
    
    예상 출력
    2
    
  2. 예제 2

    입력
    4 3 2
    1 4
    1 2 1
    2 3 1
    3 4 1
    2 3
    
    예상 출력
    -1
    
  3. 예제 3

    입력
    6 6 3
    1 3
    1 2 3
    2 3 3
    1 5 2
    5 3 2
    4 5 1
    5 6 1
    4 5 3
    
    예상 출력
    6