Submission #1015496

#TimeUsernameProblemLanguageResultExecution timeMemory
1015496aufanCyberland (APIO23_cyberland)C++17
100 / 100
1350 ms71848 KiB
#include "cyberland.h" #include <bits/stdc++.h> using namespace std; const double INFF = 1e18; double solve(int n, int m, int k, int h, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) { vector<vector<pair<int, double>>> v(n); for (int i = 0; i < m; i++) { v[x[i]].push_back({y[i], c[i]}); v[y[i]].push_back({x[i], c[i]}); } k = min(k, 70); vector<vector<double>> dist(n, vector<double>(k + 1, INFF)); priority_queue<tuple<double, int, int>, vector<tuple<double, int, int>>, greater<tuple<double, int, int>>> pq; dist[0][0] = 0; pq.push({0, 0, 0}); for (int _ = 0; _ <= k; _++) { priority_queue<tuple<double, int, int>, vector<tuple<double, int, int>>, greater<tuple<double, int, int>>> tmp; while (!pq.empty()) { auto [d, x, ck] = pq.top(); pq.pop(); if (dist[x][ck] < d || x == h) continue; for (auto [z, c] : v[x]) { if (arr[z] == 0 && 0 < dist[z][ck]) { dist[z][ck] = 0; pq.push({dist[z][ck], z, ck}); } if (arr[z] == 1 && d + c < dist[z][ck]) { dist[z][ck] = d + c; pq.push({dist[z][ck], z, ck}); } if (arr[z] == 2 && d + c < dist[z][ck]) { dist[z][ck] = d + c; pq.push({dist[z][ck], z, ck}); } if (ck < k && arr[z] == 2 && (d + c) / (double) (2) < dist[z][ck + 1]) { dist[z][ck + 1] = (d + c) / (double) (2); tmp.push({dist[z][ck + 1], z, ck + 1}); } } } swap(pq, tmp); } double ans = INFF; for (int ck = 0; ck <= k; ck++) ans = min(ans, dist[h][ck]); // loh bisa -1 return (ans == INFF ? -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...