# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1004495 | 2024-06-21T09:27:42 Z | vjudge3 | Crocodile's Underground City (IOI11_crocodile) | C++17 | 0 ms | 0 KB |
#include "crocodile.h" #include <bits/stdc++.h> using namespace std; using ll = long long; vector<pair<int, ll>> g[100005]; ll di[100005][2]; const ll inf = 1e18; ll travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) { for (int i = 0; i < N; i++) di[i][0] = di[i][1] = inf; for (int i = 0; i < M; i++) { g[R[i][0]].push_back({R[i][1], L[i]}); g[R[i][1]].push_back({R[i][0], L[i]}); } using T = pair<ll, ll>; priority_queue<T, vector<T>, greater<T>> pq; for (int i = 0; i < K; i++) { pq.push({0, P[i]}); di[P[i]][0] = di[P[i]][1] = 0; } while (!pq.empty()) { auto [d, u] = pq.top(); pq.pop(); if (di[u][1] != d) continue; for (auto& [v, w] : g[u]) { if (d+w <= di[v][0]) { di[v][1] = di[v][0]; di[v][0] = d+w; if (di[v][1] != inf) pq.push({di[v][1], v}); } else if (d+w < di[v][1]) { di[v][1] = d+w; pq.push({di[v][1], v}); } } } return di[0][1]; }