/* -*- coding: utf-8 -*- * * 2805.cc: No.2805 Go to School - yukicoder */ #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 200000; const long long LINF = 1LL << 62; /* typedef */ using ll = long long; using pii = pair; using pli = pair; using vpii = vector; /* global variables */ vpii nbrs[MAX_N]; int ts[MAX_N]; ll ds0[MAX_N], ds1[MAX_N]; /* subroutines */ void dijkstra(int n, int st, ll ds[]) { fill(ds, ds + n, LINF); ds[st] = 0; priority_queue q; q.push({0, st}); while (! q.empty()) { auto [ud, u] = q.top(); q.pop(); ud = -ud; if (ds[u] != ud) continue; for (auto [v, t]: nbrs[u]) { ll vd = ud + t; if (ds[v] > vd) { ds[v] = vd; q.push({-vd, v}); } } } } /* main */ int main() { int n, m, l, s, e; scanf("%d%d%d%d%d", &n, &m, &l, &s, &e); for (int i = 0; i < m; i++) { int u, v, t; scanf("%d%d%d", &u, &v, &t); u--, v--; nbrs[u].push_back({v, t}); nbrs[v].push_back({u, t}); } for (int i = 0; i < l; i++) scanf("%d", ts + i), ts[i]--; dijkstra(n, 0, ds0); dijkstra(n, n - 1, ds1); ll mind = LINF; for (int i = 0; i < l; i++) if (ds0[ts[i]] < s + e) { ll d = max(ds0[ts[i]] , (ll)s) + 1 + ds1[ts[i]]; mind = min(mind, d); } printf("%lld\n", (mind < LINF) ? mind : -1LL); return 0; }