Submission #943967

#TimeUsernameProblemLanguageResultExecution timeMemory
943967AmaarsaaCrocodile's Underground City (IOI11_crocodile)C++14
100 / 100
397 ms91844 KiB
#include <iostream> #include <vector> #include <queue> #include <algorithm> using namespace std; #define ll long long #define INF 1e18 ll travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){ int n = N, m = M, k = K; vector<vector<pair<int, ll>>> graph(n); for (int i = 0; i < m; i++){ graph[R[i][0]].push_back({R[i][1], L[i]}); graph[R[i][1]].push_back({R[i][0], L[i]}); } ll dist[n][2]; for (int i = 0; i < n; i++){ dist[i][0] = INF, dist[i][1] = INF; } priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq; for (int i = 0; i < k; i++){ dist[P[i]][0] = 0; dist[P[i]][1] = 0; pq.push({0, P[i]}); } while (!pq.empty()){ ll cur_dis = pq.top().first; int u = pq.top().second; pq.pop(); if (cur_dis != dist[u][1]){ continue; } for (pair<int, int> p: graph[u]){ int v = p.first, w = p.second; if (dist[v][0] > w + cur_dis){ if (dist[v][0] != dist[v][1] && dist[v][0] < INF){ dist[v][1] = dist[v][0]; pq.push({dist[v][1], v}); } dist[v][0] = w+cur_dis; }else if (dist[v][1] > w + cur_dis){ dist[v][1] = w + cur_dis; pq.push({dist[v][1], v}); } } } return dist[0][1]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...