#include #define int long long // #define endl '\n' using namespace std; const int INF = 1e18; struct Edge { int u, d; }; vector> gr(10001, vector()); vector dijkstra(int start) { vector dist(gr.size(), INF); dist[start] = 0; priority_queue, vector>, greater>> q; q.push({0, start}); while (!q.empty()) { int v = q.top().second, d = q.top().first; q.pop(); if (dist[v] < d) continue; for (auto [u, d] : gr[v]) { if (dist[v] + d < dist[u]) { dist[u] = dist[v] + d; q.push({dist[u], u}); } } } return dist; } int dist[30][1 << 12]; struct Road { int v, u, d; }; int solve() { int n, m; cin >> n >> m; int r; cin >> r; vector vr; for (int i = 0; i < r; i++) { int c; cin >> c; c--; vr.push_back(c); } sort(vr.begin(), vr.end()); vector main_r; for (int i = 0; i < m; i++) { int v, u, d; cin >> v >> u >> d; v--; u--; gr[v].push_back({u, d}); gr[u].push_back({v, d}); if (vr.size() && i == vr.front()) { main_r.push_back({v, u, d}); vr.erase(vr.begin()); } } set s_main_c; for (int i = 0; i < r; i++) { s_main_c.insert(main_r[i].u); s_main_c.insert(main_r[i].v); } s_main_c.insert(0); s_main_c.insert(n - 1); vector main_c(s_main_c.begin(), s_main_c.end()); int k = main_c.size(); int mat[k][k]; for (int i = 0; i < k; i++) { vector dist = dijkstra(main_c[i]); for (int j = 0; j < k; j++) { mat[i][j] = dist[main_c[j]]; } } for (int i = 0; i < k; i++) { for (int j = 0; j < (1 << r); j++) { dist[i][j] = INF; } dist[i][0] = mat[0][i]; } for (int s = 1; s < (1 << r); s++) { for (int i = 0; i < r; i++) { if (s & (1 << i)) { int v = main_r[i].v, u = main_r[i].u, d = main_r[i].d; dist[v][s] = min(dist[v][s], dist[u][s ^ (1 << i)] + d); dist[u][s] = min(dist[u][s], dist[v][s ^ (1 << i)] + d); for (int j = 0; j < k; j++) { dist[j][s] = min(dist[j][s], dist[v][s] + mat[v][j]); dist[j][s] = min(dist[j][s], dist[u][s] + mat[u][j]); } } } } cout << 1 << endl; // cout << dist[k - 1][(1 << r) - 1] << endl; return 1; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }