# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
642558 | 2022-09-20T01:08:35 Z | Blossomstream | Crocodile's Underground City (IOI11_crocodile) | C++14 | 0 ms | 0 KB |
#include<bits/stdc++.h> using namespace std; using ll = long long; int n, m, k; ll d[100000][2]; vector<pair<int, int> > adj[100000]; vector<int> p; bool visited[100000]; ll MAX_DIST = 1000000001; ll dijkstra() { for(int i = 0; i < n; i++) { d[i][0] = MAX_DIST; d[i][1] = MAX_DIST; } priority_queue<pair<ll, int> > q; for(int v: p) { d[v][0] = 0; d[v][1] = 0; q.push(make_pair(0LL, v)); } while(!q.empty()) { int v = q.top().second; q.pop(); if(visited[v]) continue; visited[v] = true; for(auto u: adj[v]) { if(visited[u.first]) continue; if(d[v][1] + (ll) u.second <= d[u.first][0]) { d[u.first][1] = d[u.first][0]; d[u.first][0] = d[v][1] + (ll) u.second; } else { d[u.first][1] = min(d[u.first][1], d[v][1] + (ll) u.second); } q.push(make_pair(-d[u.first][1], u.first)); } } return d[0][1]; } int main() { cin >> n >> m >> k; for(int i = 0; i < m; i++) { int a, b, l; cin >> a >> b >> l; adj[a].push_back(make_pair(b, l)); adj[b].push_back(make_pair(a, l)); } for(int i = 0; i < k; i++) { int a; cin >> a; p.push_back(a); } cout << dijkstra() << endl; }