Submission #583420

#TimeUsernameProblemLanguageResultExecution timeMemory
583420Drew_Crocodile's Underground City (IOI11_crocodile)C++17
46 / 100
144 ms262144 KiB
#include "crocodile.h" #include <bits/stdc++.h> using namespace std; #define pb push_back #define f1 first #define s2 second using ll = long long; using ii = pair<int, int>; using pl = pair<ll, ll>; const int MAX = 1e5 + 69; const ll inf = (ll) 1e18 + 69; vector<ii> adj[MAX]; pl cost[MAX]; inline void dfs(int node, int par) { if (cost[node].f1 == 0) return; const auto merge = [](pl x, ll y) -> pl { if (x.f1 > y) swap(x.f1, y); if (x.s2 > y) swap(x.s2, y); if (x.f1 > x.s2) swap(x.f1, x.s2); return x; }; for (auto &[to, w] : adj[node]) if (to != par) { dfs(to, node); cost[node] = merge(cost[node], w + cost[to].s2); } } int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) { for (int i = 0; i < N; ++i) cost[i] = { inf, inf }; for (int i = 0; i < M; ++i) { adj[ R[i][0] ].pb({ R[i][1], L[i] }); adj[ R[i][1] ].pb({ R[i][0], L[i] }); } priority_queue<pair<pl, int>> pq; for (int i = 0; i < K; ++i) { cost[P[i]] = { 0, 0 }; // pq.push({ {0, 0}, P[i] }); } dfs(0, -1); return cost[0].s2; const auto merge = [](pl x, ll y) -> pl { if (x.f1 > y) swap(x.f1, y); if (x.s2 > y) swap(x.s2, y); if (x.f1 > x.s2) swap(x.f1, x.s2); return x; }; while (!pq.empty()) { auto [C, node] = pq.top(); pq.pop(); C.f1 = -C.f1; C.s2 = -C.s2; if (C != cost[node]) continue; for (auto &[to, w] : adj[node]) { pl nxt = merge(cost[to], C.s2 + w); if (nxt < cost[to]) { cost[to] = nxt; pq.push({{-nxt.f1, -nxt.s2}, to}); } } } return (int)cost[0].s2; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...