#include #include #include #include #include #include #include #include using namespace std; struct Func_print { void is_true(bool yes) { cout << (yes ? "Yes" : "No") << '\n'; }; void print_v_str(vector v) { for (auto s : v) { for (auto c : s) { cout << c << ' '; } cout << '\n'; } } void print_vv(vector> vv) { for (auto v : vv) { for (auto d : v) { cout << d << ' '; } cout << '\n'; } } }; Func_print Out;//出力用 #define REP(i, n) for (int i = 0; i < (n); i++) #define VEC(type, name, n) vector name(n); REP(i, n) cin >> name.at(i) #define VV(type, name, h, w) vector> name(h, vector(w)); REP(i, h) REP(j, w) cin >> name.at(i).at(j) #define ALL(iterable) begin(iterable), end(iterable) int main() { /////////////////////////////// //お約束 ios::sync_with_stdio(false);//printfとcoutを混在しないように注意 //doubleの桁数指定は以下を使用する //cout << fixed << setprecision() << y << endl; cin.tie(nullptr); //////////////////////////////// int N, M; cin >> N >> M; vector> edges(N+1, vector()); REP(i, M) { int u, v; cin >> u >> v; edges[u].push_back(v); edges[v].push_back(u); } vector is_yiwiy9(N+1, false);//右寄りしか勝たん!! int K; cin >> K; REP(i, K) { int a; cin >> a; is_yiwiy9[a] = true; } const int IS_NOT_PATH = 10; vector min_cnt_yiwiy9(N+1, IS_NOT_PATH); bool success = false; vector path; const int64_t INF = INT64_MAX; int64_t ans = INF; auto dfs = [&](auto self, int v) { if (success) return; if (v == N) { ans = min(ans, (int64_t)path.size() - 1); return; } int cnt_now = min_cnt_yiwiy9[v]; for (auto nv : edges[v]) { int cnt_next = cnt_now; if (is_yiwiy9[nv]) cnt_next ++; else cnt_next = 0; if (min_cnt_yiwiy9[nv] <= cnt_next) continue; if (cnt_next >= 5) continue; min_cnt_yiwiy9[nv] = cnt_next; path.push_back(nv); self(self, nv); path.pop_back(); } }; min_cnt_yiwiy9[1] = 0; path.push_back(1); dfs(dfs, 1); if (ans == INF) ans = -1; cout << ans << endl; }