//ダイクストラ高速化弱め #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 dijkstra(int n, int start, int finish, VV &route) { V path(n, -1); priority_queue, greater > pq; pq.push({ 0,start }); while (pq.size()) { Pair p = pq.top(); pq.pop(); int d = p.first; int v = p.second; if (path[v] == -1) { path[v] = d; if (v == finish) { break; } rep(i, 0, route[v].size()) { Pair p = { d + route[v][i].second,route[v][i].first }; pq.push(p); } } } return path[finish]; } int main(void) { int N, M, K; cin >> N >> M >> K; V R(K); rep(i, 0, K) { cin >> R[i]; R[i] -= 1; } sort(all(R)); 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 = inf; int rsum = 0; rep(i, 0, R.size()) { rsum += edge[R[i]][2]; } VV dist(N, V(N)); rep(rbit, 0, 1 << K) { V b(K); rep(i, 0, K) { b[i] = (rbit >> i) & 1; } VV dp(1 << K, V(K, inf)); rep(i, 0, K) { int p = edge[R[i]][b[i]]; if (dist[0][p] == 0) { dist[0][p] = dist[p][0] = dijkstra(N, 0, p, route); } dp[1 << i][i] = dist[0][p] + rsum; } rep(bit, 1, 1 << K) { rep(s, 0, K) { int p = edge[R[s]][b[s] ^ 1]; if (((bit >> s) & 1) == 0) { continue; } rep(t, 0, K) { int np = edge[R[t]][b[t]]; int k = bit | (1 << t); if (dist[p][np] == 0) { dist[p][np] = dist[np][p] = dijkstra(N, p, np, route); } int d = dp[bit][s] + dist[p][np]; if (((bit >> t) & 1) == 0 && dp[k][t] > d) { dp[k][t] = d; } } } } int c = inf; rep(i, 0, K) { int p = edge[R[i]][b[i] ^ 1]; if (dist[p][N - 1] == 0) { dist[p][N - 1] = dist[N - 1][p] = dijkstra(N, p, N - 1, route); } int d = dp[(1 << K) - 1][i] + dist[p][N - 1]; if (c > d) { c = d; } } if (ans > c) { ans = c; } } cout << ans << endl; return 0; }