# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
985320 | doducanh | 악어의 지하 도시 (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.
#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int,int>
#define fi first
#define se second
const int maxx=1e12+7;
const int maxn=1e5+7;
vector<ii>a[maxn];
bool dd[maxn];
int n,m,k;
struct Best
{
int fi,se;
bool operator <(const Best &b)const
{
return (fi<b.fi||(fi==b.fi&&se<b.se));
}
};
Best f[maxn];
#define Data pair<Best,int>
main()
{
cin>>n>>m>>k;
vector<int>exit_chamber(k);
for(int i=1;i<=m;i++){
int u,v,w;
cin>>u>>v>>w;
a[u].push_back({v,w});
a[v].push_back({u,w});
}
for(int &e:exit_chamber){
cin>>e;
dd[e]=true;
}
priority_queue<Data,vector<Data>,greater<Data>>q;
for(int i=0;i<n;i++){
if(dd[i]){
f[i]={0,0};
q.push({f[i],i});
}
else f[i]={maxx,maxx};
}
while(q.size()){
Best du=q.top().fi;
int u=q.top().se;
// cout<<du.fi<<" "<<du.se<<" "<<u<<"\n";
q.pop();
if((du.fi!=f[u].fi||du.se!=f[u].se))continue;
for(ii p:a[u]){
int v=p.fi;
int w=p.se;
int canh=w+du.se;
Best tmp=f[v];
if(tmp.fi>canh){
tmp.se=tmp.fi;
tmp.fi=canh;
}
else if(tmp.se>canh){
tmp.se=canh;
}
if(tmp<f[v]){
f[v]=tmp;
q.push({tmp,v});
}
}
}
cout<<f[0].se;
return 0;
}