This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "cyberland.h"
#include<bits/stdc++.h>
using namespace std;
const double INF = 1e18;
struct Data{
int u;
double w;
Data(int _u, double _w) : u(_u), 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<double>d(n, INF);
q.emplace(0, d[0] = 0.0);
double ans = INF;
for(int i = min(k, 80); i > -1; i--){
vector<double>D(n, INF);
priority_queue<Data>Q;
while(!q.empty()){
auto [u, w] = q.top();
q.pop();
if(w > d[u] || u == h){
continue;
}
for(auto& [v, weight] : e[u]){
if(arr[v] == 0){
if(d[v] > 0.0){
q.emplace(v, d[v] = 0.0);
}
}
else{
double W = w + double(weight);
if(W < d[v]){
q.emplace(v, d[v] = W);
}
if(arr[v] == 2 && i > 0 && (W /= 2.0) < D[v]){
Q.emplace(v, D[v] = W);
}
}
}
}
if(ans > d[h])ans = d[h];
d = D;
q = Q;
}
return ans == INF ? -1 : ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |