Submission #983060

#TimeUsernameProblemLanguageResultExecution timeMemory
983060c2zi6Cyberland (APIO23_cyberland)C++17
44 / 100
35 ms10324 KiB
#define _USE_MATH_DEFINES #include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define all(a) (a).begin(), (a).end() #define replr(i, a, b) for (int i = int(a); i <= int(b); ++i) #define reprl(i, a, b) for (int i = int(a); i >= int(b); --i) #define rep(i, n) for (int i = 0; i < int(n); ++i) #define mkp(a, b) make_pair(a, b) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<PII> VPI; typedef vector<VI> VVI; typedef vector<VVI> VVVI; typedef vector<VPI> VVPI; typedef pair<ll, ll> PLL; typedef vector<ll> VL; typedef vector<PLL> VPL; typedef vector<VL> VVL; typedef vector<VVL> VVVL; typedef vector<VPL> VVPL; template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;} template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;} #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; template<class T> using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #include "cyberland.h" void dijkstra(VVPI& gp, VL& dist, int s) { int n = gp.size(); priority_queue<PLL> pq; VI vis(n); dist = VL(n, 1e18); dist[s] = 0; pq.push({0, s}); while (pq.size()) { int u = pq.top().ss; pq.pop(); if (vis[u]) continue; vis[u] = true; for (auto[v, w] : gp[u]) { if (dist[u] + w < dist[v]) { dist[v] = dist[u] + w; pq.push({-dist[v], v}); } } } } int n, m, k, h; VVPI gp; VI col; ll ans; VI vis; void dfs(int u, VL& dist) { if (u == h) return; if (col[u] == 0) setmin(ans, dist[u]); vis[u] = true; for (auto[v, w] : gp[u]) if (!vis[v]) dfs(v, dist); } double solve(int N, int M, int K, int H, VI X, VI Y, VI C, VI ARR) { n = N, m = M, k = K, h = H; col = ARR; gp = VVPI(n); rep(i, m) { int u = X[i]; int v = Y[i]; int w = C[i]; gp[u].pb({v, w}); gp[v].pb({u, w}); } VL dist; dijkstra(gp, dist, h); /* for (ll x : dist) cout << x << " "; */ /* cout << endl; */ if (dist[0] == 1e18) return -1; vis = VI(n); ans = dist[0]; dfs(0, dist); return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...