#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)); do { rep(bit, 0, 1 << K) { int s = rsum; V path(1); rep(i, 0, K) { int b = (bit >> i) & 1; path.push_back(edge[R[i]][b]); path.push_back(edge[R[i]][b ^ 1]); } path.push_back(N - 1); for (int i = 0; i < path.size() - 1; i += 2) { if (dist[path[i]][path[i + 1]] == 0) { dist[path[i]][path[i + 1]] = dist[path[i + 1]][path[i]] = dijkstra(N, path[i], path[i + 1], route); } s += dist[path[i]][path[i + 1]]; } if (ans > s) { ans = s; } } } while (next_permutation(all(R))); cout << ans << endl; return 0; }