제출 #750786

#제출 시각아이디문제언어결과실행 시간메모리
750786rxlfd314사이버랜드 (APIO23_cyberland)C++17
40 / 100
363 ms20872 KiB
#include "cyberland.h" #include <bits/stdc++.h> using namespace std; double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) { vector<pair<int, double>> adj[N]; for (int i = 0; i < M; i++) { adj[x[i]].push_back({y[i], (double)c[i]}); adj[y[i]].push_back({x[i], (double)c[i]}); } bool useful[N] = {}; queue<int> qu; qu.push(0); useful[0] = true; while (qu.size()) { int f = qu.front(); qu.pop(); if (f == H) continue; for (auto [nf, _] : adj[f]) { if (!useful[nf]) { useful[nf] = true; qu.push(nf); } } } vector<vector<double>> dst(min(K, 80)+1, vector<double>(N, 1e14)); double ans = 1e14; for (int ii = 0; ii <= min(K, 80); ii++) { priority_queue<pair<double, int>> pq; for (int i = 0; i < N; i++) { if (!useful[i]) continue; if (arr[i] == 2 && ii) { for (auto [j, v] : adj[i]) { if (!useful[j] || j == H) continue; dst[ii][i] = min(dst[ii][i], (dst[ii-1][j] + v) / 2.0); } pq.push({dst[ii][i], i}); } else if (!arr[i]) { dst[ii][i] = 0; pq.push({0, i}); } } if (!ii) { dst[0][0] = 0; pq.push({0, 0}); } while (pq.size()) { auto [d, f] = pq.top(); pq.pop(); if (f == H) continue; for (auto [nf, v] : adj[f]) { if (d + v < dst[ii][nf] && useful[nf] && arr[nf] == 1) { dst[ii][nf] = d + v; pq.push({d+v, nf}); } } } ans = min(ans, dst[ii][H]); } 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...