Submission #297764

#TimeUsernameProblemLanguageResultExecution timeMemory
297764Haunted_CppCrocodile's Underground City (IOI11_crocodile)C++17
0 / 100
2 ms2688 KiB
#include "crocodile.h" #include <bits/stdc++.h> using namespace std; const int MAX_N = 1e5 + 5; vector<vector<pair<int, int>>> g(MAX_N); int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) { for (int i = 0; i < M; i++) { g[R[i][0]].emplace_back(R[i][1], L[i]); g[R[i][1]].emplace_back(R[i][0], L[i]); } priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; vector<int> closest_one(N, 1e9); for (int i = 0; i < K; i++) { closest_one[P[i]] = 0; pq.emplace(closest_one[P[i]], P[i]); } while(!pq.empty()) { auto [w, node] = pq.top(); pq.pop(); if (w != closest_one[node]) { continue; } for (auto [to, cost] : g[node]) { if (closest_one[to] > closest_one[node] + cost) { closest_one[to] = closest_one[node] + cost; pq.emplace(closest_one[to], to); } } } vector<int> dist(N, 1e9); dist[0] = 0; pq.emplace(dist[0], 0); while(!pq.empty()) { auto [w, node] = pq.top(); pq.pop(); if (w != dist[node]) { continue; } pair<int, int> is_blocked = {1e9, 1e9}; for (auto [to, cost] : g[node]) { is_blocked = min(is_blocked, {closest_one[to] + cost , to}); } for (auto [to, cost] : g[node]) { if (to == is_blocked.second) { continue; } if (dist[to] > dist[node] + cost) { dist[to] = dist[node] + cost; pq.emplace(dist[to], to); } } } int best_way = 1e9; for (int i = 0; i < K; i++) { best_way = min(best_way, dist[P[i]]); } return best_way; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...