# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
16397 | 2015-08-22T10:34:16 Z | comet | Crocodile's Underground City (IOI11_crocodile) | C++ | 0 ms | 0 KB |
#include<cstdio> #include<algorithm> #include<queue> #include<vector> #include<cstring> using namespace std; typedef pair<int,int> pp; typedef vector<pp> vec; vector<vector<pp>> path; int d[100000][2],INF; bool visit[100000]; int travel_plan(int N,int M,int R[][2],int L[],int K,int P[]){ path.assign(N,vec()); memset(d,0x3f,sizeof(d)); INF=d[0][0]; for(int i=0;i<M;i++){ path[R[i][0]].push_back(pp(R[i][1],L[i])); path[R[i][1]].push_back(pp(R[i][0],L[i])); } priority_queue<pp> Q; for(int i=0;i<K;i++){ Q.push(pp(0,P[i])); d[P[i]][1]=d[P[i]][0]=0; } int v,dist; while(!Q.empty()){ do{ v=Q.top().second; dist=-Q.top().first; Q.pop(); }while(visit[v]); visit[v]=1; for(int i=0;i<path[v].size();i++){ int u=path[v][i].first; int c=path[v][i].second; if(d[u][0]>=dist+c){ swap(d[u][0],d[u][1]); d[u][0]=dist+c; if(d[u][1]<INF)Q.push(pp(-d[u][1],u)); } else if(d[u][1]>dist+c){ d[u][1]=dist+c; Q.push(pp(-d[u][1],u)); } } } return d[0][1]; }