# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
499577 | 2021-12-28T20:07:14 Z | speedyArda | Crocodile's Underground City (IOI11_crocodile) | C++17 | 0 ms | 0 KB |
#include "bits/stdc++.h" #define pb push_back using ll = long long; using namespace std; const int MAXN = 1e5; vector<int> visited(MAXN + 5); vector<vector<pair<ll, int> > > adj(MAXN + 5); int main() { int n, m, k; cin >> n >> m >> k; for(int i = 1; i <= m; i++) { ll f, s, d; cin >> f >> s >> d; adj[f].pb({d, s}); adj[s].pb({d, f}); } set<pair<ll, int> > q; for(int i = 1; i <= k; i++) { ll f; cin >> f; q.insert({0, f}); visited[f] = 1; } ll ans; while(!q.empty()) { int v = q.begin()->second; ll dist = q.begin()->first; q.erase(q.begin()); if(visited[v] == 0) { visited[v] = 1; continue; } if(v == 0) { ans = dist; break; } visited[v] = 2; for(auto e : adj[v]) { int edge = e.second; ll cost = e.first; if(visited[edge] == 2) continue; q.insert({cost + dist, edge}); } } cout << ans << "\n"; }