#include static inline constexpr std::vector> prepare_graph(const uint_fast32_t N, const std::vector>& edges) noexcept { std::vector> next_of(N + 1); for (const auto& [u, v] : edges) next_of[u].push_back(v), next_of[v].push_back(u); return next_of; } static inline constexpr std::vector prepare_creature(const uint_fast32_t N, const std::vector& A) noexcept { std::vector is_there_creature(N + 1, false); for (const auto& a : A) is_there_creature[a] = true; return is_there_creature; } // 再進入BFS解法 static inline int_fast32_t solve(const uint_fast32_t N, const std::vector>& next_of, const std::vector& is_there_creature) noexcept { std::vector> dist(N + 1, { 5, UINT_FAST32_MAX }); std::queue q; dist[1] = { 0, 0 }, q.push(1); while (!q.empty()) { const auto& cur_pos = q.front(); for (const auto& next : next_of[cur_pos]) { if (is_there_creature[next]) // もし岩井星人がいるなら { if (dist[next].first > dist[cur_pos].first + 1) // 前回の進入時よりも欲望を抑えられているなら dist[next] = { dist[cur_pos].first + 1, dist[cur_pos].second + 1 }, q.push(next); } else if (dist[next].second == UINT_FAST32_MAX) // 未踏のマスなら dist[next] = { 0, dist[cur_pos].second + 1 }, q.push(next); } q.pop(); } return dist[N].second; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); uint_fast32_t N, M, K; std::cin >> N >> M; std::vector> edges(M); for (auto& [u, v] : edges) std::cin >> u >> v; std::cin >> K; std::vector A(K); for (auto& a : A) std::cin >> a; std::cout << solve(N, prepare_graph(N, edges), prepare_creature(N, A)) << '\n'; return 0; }