# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1187984 | pxsit | Crocodile's Underground City (IOI11_crocodile) | C++20 | 0 ms | 0 KiB |
#include <bits/extc++.h>
using namespace std;
typedef long long ll;
ll travel_plan(int N, int M, int R[][2], ll L[], int K, int P[]){
int n=N, m=M, k=K;
vector<vector<pair<int,ll>>> g(n);
for(int i=0;i<m;i++){
int u=R[i][0], v=R[i][1];
ll w=L[i];
g[u].emplace_back(v,w);
g[v].emplace_back(u,w);
}
const ll INF = 4e18;
vector<ll> b1(n,INF), b2(n,INF), f(n,INF);
priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> pq;
for(int i=0;i<k;i++){
int p=P[i];
b1[p]=0;
f[p]=0;
pq.emplace(0,p);
}
while(!pq.empty()){
auto t=pq.top(); pq.pop();
ll d=t.first; int u=t.second;
if(d!=f[u]) continue;
if(u==0) break;
for(auto &e:g[u]){
int v=e.first;
ll nd=d+e.second;
if(nd<b1[v]){
b2[v]=b1[v];
b1[v]=nd;
} else if(nd<b2[v]){
b2[v]=nd;
} else continue;
ll nf=b2[v];
if(nf<f[v]){
f[v]=nf;
pq.emplace(nf,v);
}
}
}
return f[0];
}