Submission #985700

#TimeUsernameProblemLanguageResultExecution timeMemory
985700siewjhCyberland (APIO23_cyberland)C++17
97 / 100
3030 ms312300 KiB
#include "cyberland.h" #include <bits/stdc++.h> using namespace std; typedef long double ld; typedef tuple<ld, int, int> t3; const int MAXN = 100005; const ld inf = 1e18; vector<pair<int, int>> adj[MAXN]; bool vis[MAXN]; ld dist[MAXN][70]; double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr){ K = min(K, 68); for (int i = 0; i < N; i++){ adj[i].clear(); vis[i] = 0; for (int j = 0; j <= K; j++) dist[i][j] = inf; } for (int i = 0; i < M; i++){ adj[x[i]].push_back({y[i], c[i]}); adj[y[i]].push_back({x[i], c[i]}); } priority_queue<t3, vector<t3>, greater<t3>> pq; pq.push({0, 0, 0}); dist[0][0] = 0; queue<int> q; q.push(0); vis[0] = 1; while (!q.empty()){ int x = q.front(); q.pop(); if (x == H) continue; if (arr[x] == 0){ pq.push({0, x, 0}); dist[x][0] = 0; } for (auto &[nn, nd] : adj[x]) if (!vis[nn]){ q.push(nn); vis[nn] = 1; } } while (!pq.empty()){ ld d; int x, use; tie(d, x, use) = pq.top(); pq.pop(); if (dist[x][use] != d) continue; if (x == H) continue; for (auto &[nn, nd] : adj[x]){ ld fd = d + nd; if (dist[nn][use] > fd){ dist[nn][use] = fd; pq.push({dist[nn][use], nn, use}); } if (arr[nn] == 2 && use < K && dist[nn][use + 1] > fd / 2){ dist[nn][use + 1] = fd / 2; pq.push({dist[nn][use + 1], nn, use + 1}); } } } ld ans = inf; for (int use = 0; use <= K; use++) ans = min(ans, dist[H][use]); return (ans == inf ? -1 : 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...