//η„Όγιˆγ— #include #include #include #define rep(i, l, n) for (int i = (l); i < (n); i++) using namespace std; using Pair = pair; template using V = vector; template using VV = V >; const int inf = 2000000000; using chrono::duration_cast; using chrono::milliseconds; using chrono::system_clock; inline int getnow() { return duration_cast(system_clock::now().time_since_epoch()).count(); } VV dijkstra(int n, VV& edge, V& R, VV& route) { VV dist(n, V(0)); V st = { 0,n - 1 }; rep(i, 0, R.size()) { st.push_back(edge[R[i]][0]); st.push_back(edge[R[i]][1]); } rep(i, 0, st.size()) { int k = st[i]; V di(n, -1); priority_queue, greater > pq; pq.push({ 0,k }); int cnt = 0; while (pq.size() && cnt < n) { Pair p = pq.top(); pq.pop(); int d = p.first; int v = p.second; if (di[v] == -1) { cnt++; di[v] = d; rep(j, 0, route[v].size()) { Pair p = { d + route[v][j].second,route[v][j].first }; pq.push(p); } } } dist[k] = di; } return dist; } int main(void) { srand(time(NULL)); int start = getnow(); 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 rsum = 0; rep(i, 0, R.size()) { rsum += edge[R[i]][2]; } VV dist = dijkstra(N, edge, R, route); V p = {}; rep(i, 0, K) { p.push_back(i); } VV idp(K, V(2, inf)); rep(i, 0, K) { rep(j, 0, 2) { idp[i][j] = rsum + dist[0][edge[R[i]][j]]; } } int ans = inf; int tans = inf; while (getnow() - start < 4900) { int x = rand() % K; int y = rand() % K; int tmp = p[x]; p[x] = p[y]; p[y] = tmp; V q = p; VV dp = idp; rep(k, 0, K - 1) { int s = p[k]; int t = p[k + 1]; rep(i, 0, 2) { rep(j, 0, 2) { int d = dp[s][i ^ 1] + dist[edge[R[s]][i]][edge[R[t]][j]]; if (dp[t][j] > d) { dp[t][j] = d; } } } } int a = inf; rep(j, 0, 2) { int d = dp[K - 1][j ^ 1] + dist[edge[R[K - 1]][j]][N - 1]; if (a > d) { a = d; } } if (ans >= a) { ans = a; } else if (rand() % 100 != 99) { rep(i, 0, K) { p[i] = q[i]; } tans = ans; ans = a; } } if (ans > tans) { ans = tans; } cout << ans << endl; return 0; }