Submission #738869

#TimeUsernameProblemLanguageResultExecution timeMemory
738869onlk97Crocodile's Underground City (IOI11_crocodile)C++14
100 / 100
542 ms94992 KiB
#include "crocodile.h" #include <bits/stdc++.h> using namespace std; int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){ #define x first #define y second #define pb push_back vector <pair <long long,long long> > g[N]; for (int i=0; i<M; i++){ g[R[i][0]].pb({R[i][1],L[i]}); g[R[i][1]].pb({R[i][0],L[i]}); } bool visited[N]; for (int i=0; i<N; i++) visited[i]=0; pair <long long,long long> mn[N],smn[N]; for (int i=0; i<N; i++){ mn[i]={1e18,1e18}; smn[i]={1e18,1e18}; } priority_queue <pair <long long,long long>,vector <pair <long long,long long> >,greater <pair <long long,long long> > > pq; for (int i=0; i<K; i++){ mn[P[i]]={0,-1}; smn[P[i]]={0,-2}; pq.push({0,P[i]}); } while (!pq.empty()){ pair <long long,long long> tp=pq.top(); pq.pop(); if (visited[tp.y]) continue; visited[tp.y]=1; for (pair <long long,long long> i:g[tp.y]){ if (visited[i.x]) continue; if (mn[i.x].y==tp.y||smn[i.x].y==tp.y) continue; long long ndist=tp.x+i.y; if (ndist<=mn[i.x].x){ smn[i.x]=mn[i.x]; mn[i.x]={ndist,tp.y}; pq.push({smn[i.x].x,i.x}); } else if (ndist<smn[i.x].x){ smn[i.x]={ndist,tp.y}; pq.push({smn[i.x].x,i.x}); } } } return smn[0].x; #undef x #undef y #undef pb }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...