# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1039428 | sssamui | 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 <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, k;
cin >> n >> m >> k;
vector<int> min1(n, 1e9 + 1), min2(n, 1e9 + 1);
vector<vector<pair<int, int>>> adj(n, vector<pair<int, int>>(0));
while (m--)
{
int a, b, c;
cin >> a >> b >> c;
adj[a].push_back({ c, b }), adj[b].push_back({ c, a });
}
priority_queue<pair<int, int>> djk;
vector<bool> prc(n, false);
while (k--)
{
int stt;
cin >> stt;
min1[stt] = 0, min2[stt] = 0;
djk.push({ 0, stt });
}
while (!djk.empty())
{
int d = -djk.top().first, node = djk.top().second;
djk.pop();
if ((d == min2[node]) && !prc[node])
{
prc[node] = true;
for (pair<int, int> nxt : adj[node])
{
if (d + nxt.first < min1[nxt.second])
{
min2[nxt.second] = min1[nxt.second];
min1[nxt.second] = d + nxt.first;
djk.push({ -d - nxt.first, nxt.second });
}
else if (d + nxt.first < min2[nxt.second])
{
min2[nxt.second] = d + nxt.first;
djk.push({ -d - nxt.first, nxt.second });
}
}
}
}
cout << min2[0];
}