# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1081336 | nrg_studio | Crocodile's Underground City (IOI11_crocodile) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<ll,ll>
#define f first
#define s second
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int n, m, k, a, b, w; cin >> n >> m >> k;
vector<vector<pii>> adj(n);
F0R(i,m) {
cin >> a >> b >> w;
adj[a].pb({b,w});
adj[b].pb({a,w});
}
vector<pii> mn(n,{LLONG_MAX,LLONG_MAX});
priority_queue<pii,vector<pii>,greater<pii>> pq;
F0R(i,k) {
cin >> a;
mn[a] = {0,0};
pq.push({0,a});
}
while (pq.size()) {
pii cur = pq.top(); pq.pop();
if (cur.f != mn[cur.s].s) {continue;}
for (pii qwerty : adj[cur.s]) {
int cand = qwerty.s+cur.f, x = qwerty.f;
if (cand < mn[x].s) {
if (cand <= mn[x].f) {
mn[x].s = mn[x].f; mn[x].f = cand;
} else {mn[x].s = cand;}
pq.push({mn[x].s,x});
}
}
} cout << mn[0].s << '\n';
}