# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1017028 | 2024-07-08T18:06:51 Z | Kodik | Crocodile's Underground City (IOI11_crocodile) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; #define ss second #define ff first typedef long long ll; #define int ll int mod = 1e9+7; int inf = 1e18; signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); // ifstream cin ("shortcut.in"); // ofstream cout ("shortcut.out"); int n, m, k; cin >> n >> m >> k; vector<vector<pair<int,int>>> adj(n); for(int i = 0; i < m; ++i){ int a,b,c; cin >> a >> b >> c; adj[a].push_back({b,c}); adj[b].push_back({a,c}); } set<int> exit; for(int i = 0; i < k; ++i){ int x; cin >> x; exit.insert(x); } priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq; vector<int> dis(n, 1e10); int ans = 1e10; dis[0] = 0; pq.push({0,0}); bool pass = 0; while(!pq.empty()){ pair<int,int> a = pq.top(); pq.pop(); if(dis[a.ss]!=a.ff){ continue; } if(exit.find(a.ss)!=exit.end()){ ans = min(ans, a.ff); } pass = false; for(auto &[nxt, w] : adj[a.ss]){ if(a.ff+w<nxt&&pass){ pq.push({a.ff+w,nxt}); }else if(a.ff+w>=nxt){ continue; } pass = true; } } cout << ans << '\n'; return 0; }