Hurry the Hedgehog

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

요약
무향 그래프에서 1번에서 n번까지 이동할 때 지나는 모든 교차점에 Super Mushroom이 있도록 하는 최단 경로의 교차점 수를 구한다.
난이도

보통10점 중 6점

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

문제

Hurry is a Hedgehog, who lives in the Mushroom Kingdom. He is on a mission to save Princess Plum from the evil Donkey Kong. In order to get to the Princess, Hurry must run through a hyperspace network of roads. These roads are dangerous and for every road that he walks between two intersections, he is getting attacked by Space Invaders. Luckily, at some intersections, there is a Super Mushroom that will restore Hurry's health.

Can you find the shortest path through the network of roads, such that you can eat a Super Mushroom at each intersection?

입력

The intersections are numbered between 11 and nn, inclusive. \\ Hurry will need to start at intersection 11 and run to intersection nn. \\ The input is structured as follows:

  • One line with three integers: 1≤n≤1051 \leq n \leq 10^5, the number of intersections; 0≤m≤1060 \leq m \leq 10^6, the number of roads; and 1≤s≤n1 \leq s \leq n, the number of Super Mushrooms.
  • One line with max⁡(0,s−2)\max(0, s-2) integers: the indices of the intersections that have a Super Mushroom (intersections 11 and nn will always have a Super Mushroom and are not in this list).
  • mm lines with two integers each, indicating that there is a road between the two intersections with these indices.

출력

One line containing one integer, which is the number of intersections in the path that Hurry will have to run.

예제2

  1. 예제 1

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

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