Submission #537765

#TimeUsernameProblemLanguageResultExecution timeMemory
537765timreizinCrocodile's Underground City (IOI11_crocodile)C++17
100 / 100
618 ms119692 KiB
#include "crocodile.h" #include <vector> #include <queue> using namespace std; using ll = long long; ll dijkstra(vector<int> starts, vector<vector<pair<int, ll>>> adj) { int n = adj.size(); vector<pair<ll, ll>> dist(n, {1e12, 1e12}); priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<>> pq; vector<bool> used(n); for (int i : starts) { dist[i].first = dist[i].second = 0; pq.push({0, i}); } while (!pq.empty()) { int v = pq.top().second; pq.pop(); if (used[v]) continue; used[v] = true; for (auto [u, w] : adj[v]) { if (dist[u].first > dist[v].second + w) { dist[u].second = dist[u].first; dist[u].first = dist[v].second + w; if (dist[u].second != 1e12) pq.push({dist[u].second, u}); } else if (dist[u].second > dist[v].second + w) { dist[u].second = dist[v].second + w; pq.push({dist[u].second, u}); } } } return dist[0].second; } int travel_plan(int n, int m, int R[][2], int L[], int k, int P[]) { vector<int> starts(k); for (int i = 0; i < k; ++i) starts[i] = P[i]; vector<vector<pair<int, ll>>> adj(n); for (int i = 0; i < m; ++i) { adj[R[i][0]].emplace_back(R[i][1], L[i]); adj[R[i][1]].emplace_back(R[i][0], L[i]); } return dijkstra(starts, adj); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...