Submission #983142

#TimeUsernameProblemLanguageResultExecution timeMemory
983142c2zi6Cyberland (APIO23_cyberland)C++17
37 / 100
35 ms10076 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" typedef vector<vector<pair<int, ll>>> GRAPH; void dijkstra(GRAPH& gp, vector<ll>& dist, int s) { int n = gp.size(); priority_queue<pair<int, ll>> pq; dist = vector<ll>(n, 1e18); dist[s] = 0; pq.push({0, s}); VI vis(n); 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; GRAPH gp; VI col; ll ans; VI vis; void dfs(int u, vector<ll>& dist) { if (u%n == h) return; if (col[u%n] == 0) setmin(ans, dist[u]); vis[u] = true; for (auto[v, w] : gp[u]) if (!vis[v]) dfs(v, dist); } /* 1 3 3 30 1 1 1 0 0 1 1000000010 1 2 1000000000 0 2 1000000100 */ 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 = GRAPH(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}); } vector<ll> dist; dijkstra(gp, dist, h); if (dist[0] == 1e18) return -1; vis = VI(gp.size()); 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...