# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
42304 | wzy | 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 "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define pii pair<int,int>
#define eps (int) 1e9
ll d[100005][2];
vector<pii> adj[100005];
bool cc[100005] , vis[100005];
int travel_plan(int n, int m, int R[][2], int l[], int k, int p[]){
for(int i = 0 ; i <m ;i++){
adj[R[i][0]].pb(pii(l[i],R[i][1]));
adj[R[i][1]].pb(pii(l[i],R[i][0]));
}
for(int i = 0 ; i <n;i++){
d[i][0] = eps;
d[i][1] = eps;
}
priority_queue<pii , vector<pii> , greater<pii> > pq;
for(int i = 0 ; i < k ;i++){
int x;
x = p[i];
cc[x] = true;
d[x][0] = 0;
d[x][1] = 0;
pq.push(pii(0,x));
}
while(!pq.empty()){
pii u = pq.top();
pq.pop();
if(vis[u.S]) continue;
vis[u.S] = true;
for(int j = 0 ; j <adj[u.S].size();j++){
pii v = adj[u.S][j];
if(d[u.S][1] + v.F < d[v.S][0]){
swap(d[v.S][0] , d[v.S][1]);
d[v.S][0] = d[u.S][1] + v.F;
pq.push(pii(d[v.S][1],v.S));
}
else if(d[u.S][1] + v.F < d[v.S][1]){
d[v.S][1] = d[u.S][1] + v.F;
pq.push(pii(d[v.S][1] , v.S));
}
}
}
return d[0][1];
}