# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
985320 | doducanh | 악어의 지하 도시 (IOI11_crocodile) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}