#include #include #include using namespace std; using namespace atcoder; #define rep(i, l, n) for (int i = (l); i < (n); i++) #define ite(i, a) for(auto& i : a) #define all(x) x.begin(), x.end() #define lb lower_bound #define ub upper_bound #define lbi(A, x) (ll)(lb(all(A), x) - A.begin()) #define ubi(A, x) (ll)(ub(all(A), x) - A.begin()) using ll = long long; using Pair = pair; template using V = vector; template using VV = V >; const ll INF = 1000000000000000001; const int inf = 2000000000; const ll mod = 1000000007; const ll MOD = 998244353; template inline V getList(int n) { V res(n); rep(i, 0, n) { cin >> res[i]; }return res; } template inline VV getGrid(int m, int n) { VV res(m, V(n)); rep(i, 0, m) { res[i] = getList(n); }return res; } inline V dtois(string& s) { V vec = {}; for (auto& e : s) { vec.push_back(e - '0'); } return vec; } V dijkstra(int s, int n, VV& route) { V dist(n, -1); priority_queue, greater > pq; pq.push({ 0,s }); int cnt = 0; while (pq.size() and cnt < n) { Pair p = pq.top(); pq.pop(); int d = p.first; int v = p.second; if (dist[v] == -1) { dist[v] = d; cnt++; rep(j, 0, route[v].size()) { Pair p = { d + route[v][j].second,route[v][j].first }; pq.push(p); } } } return dist; } int main(void) { int n, m, k; cin >> n >> m >> k; V r(k); rep(i, 0, k) { cin >> r[i]; r[i]--; } VV route(n, V(0)); VV edge(m, V(3)); rep(i, 0, m) { rep(j, 0, 3) { cin >> edge[i][j]; } edge[i][0]--; edge[i][1]--; route[edge[i][0]].push_back({ edge[i][1],edge[i][2] }); route[edge[i][1]].push_back({ edge[i][0],edge[i][2] }); } VV dist(n, V(0)); set st = { 0,n - 1 }; ite(i, r) { st.insert(edge[i][0]); st.insert(edge[i][1]); } for (auto itr = st.begin(); itr != st.end(); itr++) { auto i = *itr; dist[i] = dijkstra(i, n, route); } V > dp(1 << k, VV(k, V(2, inf))); rep(i, 0, k) { rep(j, 0, 2) { dp[1 << i][i][j] = dist[0][edge[r[i]][j ^ 1]] + edge[r[i]][2]; } } rep(bit, 1, 1 << k) { rep(s, 0, k) { if (((bit >> s) & 1) == 0) { continue; } rep(t, 0, k) { if ((bit >> t) & 1) { continue; } rep(x, 0, 2) { rep(y, 0, 2) { int b = bit | (1 << t); dp[b][t][y] = min(dp[b][t][y], dp[bit][s][x] + dist[edge[r[s]][x]][edge[r[t]][y ^ 1]] + edge[r[t]][2]); } } } } } int ans = inf; rep(i, 0, k) { rep(j, 0, 2) { ans = min(ans, dp[(1 << k) - 1][i][j] + dist[edge[r[i]][j]][n - 1]); } } cout << ans << endl; return 0; }