Submission #761003

#TimeUsernameProblemLanguageResultExecution timeMemory
761003SanguineChameleonCrocodile's Underground City (IOI11_crocodile)C++17
100 / 100
368 ms61544 KiB
#include "crocodile.h" #include <bits/stdc++.h> using namespace std; const int maxN = 1e5 + 20; const int inf = 1e9 + 20; int dist[maxN]; int best1[maxN]; int best2[maxN]; vector<pair<int, int>> adj[maxN]; int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) { for (int i = 0; i < M; i++) { int u = R[i][0]; int v = R[i][1]; int w = L[i]; adj[u].emplace_back(v, w); adj[v].emplace_back(u, w); } for (int i = 0; i < N; i++) { best1[i] = inf; best2[i] = inf; dist[i] = inf; } priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> Q; for (int i = 0; i < K; i++) { dist[P[i]] = 0; Q.emplace(0, P[i]); } while (!Q.empty()) { int cur = Q.top().first; int u = Q.top().second; Q.pop(); if (dist[u] != cur) { continue; } for (auto e: adj[u]) { int v = e.first; int w = e.second; if (dist[u] + w < best1[v]) { best2[v] = best1[v]; best1[v] = dist[u] + w; } else if (dist[u] + w < best2[v]) { best2[v] = dist[u] + w; } if (best2[v] < dist[v]) { dist[v] = best2[v]; Q.emplace(dist[v], v); } } } return dist[0]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...