# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
363639 | David_M | 악어의 지하 도시 (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>
#define F first
#define S second
#define ll long long
using namespace std;
const ll INF=1e18, N=100005;
pair<ll, ll> D[N];
vector<pair<int, ll> > v[N];
priority_queue <pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > q;
int travel_plan(int n, int m, int R[][2], int L[], int k, int P[]){
for (int i=0; i<m; i++)
v[R[i][0]].push_back({R[i][1], L[i]}),
v[R[i][1]].push_back({R[i][0], L[i]});
for (int i=0; i<n; i++)D[i]={INF, INF};
for (int i=0; i<k; i++)D[p[i]]={0, 0},q.push({0, p[i]});
while(!q.empty()){
long long d=q.top().F;
int x=q.top().S;
q.pop();
if(d!=D[x].F)continue;
for (auto [y, l] : v[x]){
if(D[y].F>d+l){
D[y].F=d+l;
if(D[y].F<D[y].S)swap(D[y].F, D[y].S);
if(D[y].F!=INF)q.push({D[y].F, y});
}
}
}
return D[0].F;
}