# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
497258 | Skywk | Crocodile's Underground City (IOI11_crocodile) | C++11 | 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<string>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<math.h>
#include<queue>
#include<stack>
#define lmt 100000
#define LMT 1000000
#define mod 1000000007
#define pii pair<int, int>
#define pil pair<int, long long>
#define pli pair<long long, int>
using namespace std;
vector<pil> graph[lmt];
vector<pair<pii, long long>> edges;
long long best[LMT];
bool once[LMT];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n, m;
cin>> n>> m;
edges.resize(m);
for(int i=0; i<m; i++)
cin>> edges[i].first.first>> edges[i].first.second;
for(int i=0; i<m; i++)
cin>> edges[i].second;
for(auto e : edges)
{
int a=e.first.first, b=e.first.second;
graph[a].push_back({b, e.second});
graph[b].push_back({a, e.second});
}
priority_queue<pli, vector<pli>, greater<pli>> pq;
int k;
cin>> k;
for(int i=0, x; i<k; i++)
{
cin>> x;
pq.push({0, x});
}
for(int i=0; i<n; i++)
best[i]=-1;
while(!pq.empty())
{
auto p=pq.top();
pq.pop();
int x=p.second; long long w=p.first;
if(best[x] != -1)
continue;
if(w!=0 && !once[x])
{
once[x]=true;
continue;
}
best[x]=w;
for(auto y : graph[x])
{
if(best[y.first] != -1)
continue;
pq.push({w+y.second, y.first});
}
}
cout<< best[0];
return 0;
}