Submission #914121

#TimeUsernameProblemLanguageResultExecution timeMemory
914121SmuggingSpunCyberland (APIO23_cyberland)C++17
40 / 100
1938 ms2097152 KiB
#include "cyberland.h" #include<bits/stdc++.h> using namespace std; const double INF = 1e18; template<class T>void minimize(T& a, T b){ if(a > b){ a = b; } } struct Data{ int u, k; double w; Data(int _u, int _k, double _w) : u(_u), k(_k), w(_w) {} friend bool operator <(Data a, Data b){ return a.w > b.w; } }; 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, int>>>e(n); for(int i = 0; i < m; i++){ e[x[i]].emplace_back(y[i], c[i]); e[y[i]].emplace_back(x[i], c[i]); } priority_queue<Data>q; vector<vector<double>>d(n, vector<double>(k + 1, INF)); q.emplace(0, k, d[0][k] = 0.0); while(!q.empty()){ auto [u, remain, w] = q.top(); q.pop(); if(w > d[u][remain] || u == h){ continue; } for(auto& [v, weight] : e[u]){ if(arr[v] == 0){ if(d[v][remain] > 0.0){ q.emplace(v, remain, d[v][remain] = 0.0); } } else{ double W = w + double(weight); if(W < d[v][remain]){ q.emplace(v, remain, d[v][remain] = W); } if(arr[v] == 2 && remain > 0 && (W /= 2.0) < d[v][remain - 1]){ q.emplace(v, remain - 1, d[v][remain - 1] = W); } } } } double ans = INF; for(int i = 0; i <= k; i++){ minimize(ans, d[h][i]); } 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...