Submission #50988

#TimeUsernameProblemLanguageResultExecution timeMemory
50988aquablitz11Crocodile's Underground City (IOI11_crocodile)C++14
100 / 100
851 ms102160 KiB
#include <bits/stdc++.h> #include "crocodile.h" using namespace std; using ll = long long; using pii = pair<int, int>; using pli = pair<ll, int>; #define F first #define S second const int N = 150010; const ll INF = 1e18; ll dist1[N], dist2[N]; bool vis[N]; vector<pii> G[N]; int travel_plan(int n, int m, int R[][2], int L[], int k, int P[]) { fill(dist1, dist1+n, INF); fill(dist2, dist2+n, INF); for (int i = 0; i < m; ++i) { int u = R[i][0], v = R[i][1], w = L[i]; G[u].push_back({v, w}); G[v].push_back({u, w}); } priority_queue<pli, vector<pli>, greater<pli>> Q; for (int i = 0; i < k; ++i) { dist1[P[i]] = dist2[P[i]] = 0; Q.push({0, P[i]}); } while (!Q.empty()) { int u = Q.top().second; Q.pop(); if (vis[u]) continue; vis[u] = true; for (auto v : G[u]) if (!vis[v.F]) { bool mod = false; if (dist2[u]+v.S < dist1[v.F]) { dist2[v.F] = dist1[v.F]; dist1[v.F] = dist2[u]+v.S; mod = true; } else if (dist2[u]+v.S < dist2[v.F]) { dist2[v.F] = dist2[u]+v.S; mod = true; } if (mod && dist2[v.F] < INF) Q.push({dist2[v.F], v.F}); } } return dist2[0]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...