# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
687245 | sharaelong | 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>
#ifdef SHARAELONG
#include "../../cpp-header/debug.hpp"
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAX_N = 1e5 + 1;
const ll INF = 1e18;
vector<pll> adj[MAX_N];
pll dist[MAX_N];
void dijkstra() {
priority_queue<pll> pq;
for (int i=0; i<MAX_N; ++i) {
if (dist[i].second == 0) {
pq.push({ 0, i });
}
}
while (!pq.empty()) {
ll len = -pq.top().first;
ll here = pq.top().second;
pq.pop();
for (auto[there, c]: adj[here]) {
if (len+c < dist[there].first) {
dist[there].second = dist[there].first;
dist[there].first = len+c;
pq.push({ -dist[there].second, there });
} else if (len+c < dist[there].second) {
dist[there].second = len+c;
pq.push({ -dist[there].second, there });
}
}
}
}
void solve() {
int n, m, k;
cin >> n >> m >> k;
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});
}
for (int i=0; i<MAX_N; ++i) dist[i] = { INF, INF };
for (int i=0; i<k; ++i) {
int x;
cin >> x;
dist[x] = { 0, 0 };
}
dijkstra();
cout << dist[0].second;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
}