# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
316405 | r_v_n | 악어의 지하 도시 (IOI11_crocodile) | C++14 | 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.
using namespace std;
#include <bits/stdc++.h>
#define ll long long
int n, m, k;
vector<pair<int, int>> adj[100001];
vector<int> dist(100001, 1e8);
vector<int> have;
vector<vector<int>> dista(100001);
void dij()
{
vector<int> visited(n + 1, 0);
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
for (auto i : have)
{
/// cout<<have[i]<<endl;
// return ;
q.push({0, i});
dist[i] = 0;
dista[i].push_back(0);
visited[i]=1;
}
int val = 5;
while (!q.empty())
{
int currnode = q.top().second;
int curdis;
if (dista[currnode].size() == 1)
curdis = dista[currnode][0];
else
curdis = dista[currnode][1];
// int curdis=dista[currnode][1];
//cerr << currnode << " " << curdis << endl;
q.pop();
if (dista[currnode].back() < curdis)
continue;
for (auto it : adj[currnode])
{
if (dista[it.first].size() < 2)
{
dista[it.first].push_back(curdis + it.second);
q.push({curdis + it.second, it.first});
sort(dista[it.first].begin(), dista[it.first].end());
}
else
{
// decide if it is going to be added or not
int val1 = curdis + it.second;
if (val1 <= dista[it.first][0])
{
int v1, v2;
v1 = dista[it.first][0];
dista[it.first][0] = val1;
dista[it.first][1] = v1;
sort(dista[it.first].begin(), dista[it.first].end());
q.push({val1, it.first});
}
else if (val1 <= dista[it.first][1])
{
dista[it.first][1] = val1;
sort(dista[it.first].begin(), dista[it.first].end());
q.push({val1, it.first});
}
}
}
}
}
void solve()
{
int 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 < k; i++)
{
int a;
cin >> a;
have.push_back(a);
}
dij();
cout << dista[0][1] << endl;
}
int main()
{
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
long long int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}