# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
42303 | 2018-02-25T20:36:56 Z | wzy | Crocodile's Underground City (IOI11_crocodile) | C++11 | 0 ms | 0 KB |
#include <bits/stdc++.h> #include "crocodile.h" using namespace std; #define F first #define S second #define pb push_back #define int long long #define pii pair<int,int> #define eps (int) 1e9 int d[100005][2],n,m , k; 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]; }