#include "bits/stdc++.h" using namespace std; #define border 14 int dist[36][36]; int need[36]; int check[36]; int ans; int uni[36]; int getuni(int a){ if (uni[a] < 0) return a; else return uni[a] = getuni(uni[a]); } int connect(int a, int b){ a = getuni(a); b = getuni(b); if (a == b) return 0; if (uni[a] > uni[b]) swap(a, b); uni[a] += uni[b]; uni[b] = a; return 1; } vector> v; int spanningTree(int N){ for (int i = 0; i < N; i++) { uni[i] = -1; } int cost = 0; int count = 0; for (auto now : v){ if (check[get<1>(now)] && check[get<2>(now)]) { if (connect(get<1>(now), get<2>(now))){ cost += get<0>(now); count++; } } } ans = min(ans, cost); return cost; } int OPT[(1 << border)][35]; int minimum_steiner_tree(const vector& T, int N) { int n = N; int numT = T.size(); if (numT <= 1) return 0; for (int S = 0; S < (1 << numT); ++S) for (int x = 0; x < n; ++x) OPT[S][x] = 999999; for (int p = 0; p < numT; ++p) // trivial case for (int q = 0; q < n; ++q) OPT[1 << p][q] = dist[T[p]][q]; for (int S = 1; S < (1 << numT); ++S) { // DP step if (!(S & (S - 1))) continue; for (int p = 0; p < n; ++p) for (int E = 0; E < S; ++E) if ((E | S) == S) OPT[S][p] = min(OPT[S][p], OPT[E][p] + OPT[S - E][p]); for (int p = 0; p < n; ++p) for (int q = 0; q < n; ++q) OPT[S][p] = min(OPT[S][p], OPT[S][q] + dist[p][q]); } int ans2 = 999999; for (int S = 0; S < (1 << numT); ++S) for (int q = 0; q < n; ++q) ans2 = min(ans2, OPT[S][q] + OPT[((1 << numT) - 1) - S][q]); ans = ans2; return ans; } int main() { int N, M, T; cin >> N >> M >> T; int MAX = 999999; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { dist[i][j] = MAX; } dist[i][i] = 0; } for (int i = 0; i < M; i++) { int a, b, c; cin >> a >> b >> c; a--; b--; dist[a][b] = c; dist[b][a] = c; } vector T2; for (int i = 0; i < T; i++) { int temp; cin >> temp; temp--; T2.push_back(temp); need[temp] = 1; check[temp] = 1; } ans = 999999; if (T <= border){ for (int k = 0; k < N; k++) { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } } } ans = minimum_steiner_tree(T2, N); } else{ vector nokori; for (int i = 0; i < N; i++) { if (!need[i]) nokori.push_back(i); } for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { if (dist[i][j] > 100) continue; v.push_back(make_tuple(dist[i][j], i, j)); } } sort(v.begin(), v.end()); for (int i = 0; i < (1 << nokori.size()); i++) { for (int j = 0; j < nokori.size(); j++) { check[nokori[j]] = (i >> j) % 2; } int temp = spanningTree(N); } } cout << ans << endl; }