#include #include #include #include #include #include #define rep(i, l, n) for (int i = (l); i < (n); i++) #define all(x) x.begin(), x.end() using namespace std; using Pair = pair; template using V = vector; template using VV = V >; const int inf = 2000000000; int get_rnum(int K, VV&edge, V&R, int s, int t) { rep(i, 0, K) { if (s == edge[R[i]][0] and t == edge[R[i]][1]) { return i; } else if (s == edge[R[i]][1] and t == edge[R[i]][0]) { return i; } } return -1; } int dijkstra(int N, int K, VV&edge, V&R, VV&route) { VV dist(N, V(1 << K, inf)); priority_queue, V >, greater > > pq; pq.push({ 0,0,0 }); while (pq.size()) { V p = pq.top(); pq.pop(); int d = p[0]; int v = p[1]; int l = p[2]; if (v == N - 1 and l == (1 << K) - 1) { return d; } if (dist[v][l] == inf) { dist[v][l] = d; for (auto& r : route[v]) { int nv = r.first; int nd = r.second; int g = get_rnum(K, edge, R, v, nv); if (g == -1) { if (dist[nv][l] == inf) { pq.push({ d + nd,nv,l }); } } else { int nl = l | (1 << g); if (dist[nv][nl] == inf) { pq.push({ d + nd,nv,nl }); } } } } } assert(false); } int main(void) { int N, M, K; cin >> N >> M >> K; V R(K); rep(i, 0, K) { cin >> R[i]; R[i] -= 1; } VV edge(M, V(3)); VV route(N, V(0)); rep(i, 0, M) { rep(j, 0, 3) { cin >> edge[i][j]; } edge[i][0] -= 1; edge[i][1] -= 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] }); } int ans = dijkstra(N, K, edge, R, route); cout << ans << endl; return 0; }