#include namespace { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic pop using namespace std; using namespace atcoder; #define rep(i,n)for (int i = 0; i < int(n); ++i) #define rrep(i,n)for (int i = int(n)-1; i >= 0; --i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() template void chmax(T& a, const T& b) { a = max(a, b); } template void chmin(T& a, const T& b) { a = min(a, b); } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, k; cin >> n >> m >> k; // [state][v] struct Edge { int to; int c; int k; }; vector> to(n); VI r(k); rep(i, k) cin >> r[i], r[i]--; sort(all(r)); int nxt = 0; rep(i, m) { int a, b, c; cin >> a >> b >> c; a--, b--; if (nxt < k && r[nxt] == i) { to[a].emplace_back(Edge{b, c, nxt}); to[b].emplace_back(Edge{a, c, nxt}); nxt++; } else { to[a].emplace_back(Edge{b, c, -1}); to[b].emplace_back(Edge{a, c, -1}); } } assert(nxt == k); constexpr ll INF = 1002003004005006007; vector dist(n << k, INF); auto cmp = [](const pair& x, const pair& y) { return x.second > y.second; }; priority_queue, vector>, decltype(cmp)> q(cmp); auto push = [&](int s, int v, ll d) { int idx = s | v << k; if (d < dist[idx]) { dist[idx] = d; q.emplace(idx, d); } }; push(0, 0, 0); while(!q.empty()) { auto [idx, d] = q.top(); q.pop(); if (dist[idx] != d) continue; int u = idx >> k; int s = idx & (1 << k) - 1; for(auto [v, c, b] : to[u]) { int ns = b != -1 ? s | 1 << b : s; push(ns, v, d + c); } } cout << dist.back() << '\n'; }