Submission #124039

#TimeUsernameProblemLanguageResultExecution timeMemory
124039johuthaCrocodile's Underground City (IOI11_crocodile)C++14
100 / 100
923 ms67048 KiB
#include "crocodile.h" #include <vector> #include <iostream> #include <queue> using namespace std; vector<int> vals; vector<vector<pair<int,int>>> adjlist; int travel_plan(int n, int m, int R[][2], int L[], int k, int P[]) { vals.resize(n, -1); adjlist.resize(n); for (int i = 0; i < m; i++) { adjlist[R[i][0]].push_back({R[i][1], L[i]}); adjlist[R[i][1]].push_back({R[i][0], L[i]}); } priority_queue<pair<int,int>> pq; for (int i = 0; i < k; i++) { vals[P[i]] = -2; pq.push({0, P[i]}); } while (!pq.empty()) { int curr = pq.top().second; int val = -pq.top().first; pq.pop(); if (vals[curr] == -1) { vals[curr] = -2; continue; } if (vals[curr] > -1) continue; vals[curr] = val; for (auto p : adjlist[curr]) { if (vals[p.first] > -1) continue; pq.push({-vals[curr] - p.second, p.first}); } } return vals[0]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...