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>
#include <cmath>
using namespace std;
struct node{
int u,k;double cost;
};
double solve(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr) {
vector<vector<pair<int,int>>>adj(N);
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]});
}
vector<vector<double>>d(N,vector<double>(2,1e18));
d[0][0]=0;
auto cmp=[](node& a,node &b){return a.cost>b.cost;};
priority_queue<node,vector<node>,decltype(cmp)>pq(cmp);
pq.push({0,0,0});
double pw=1;
for(int i=0;i<K;i++)pw/=2;
double ans=1e18;
while(!pq.empty()){
auto [u,k,cost]=pq.top();pq.pop();
if(d[u][k]<cost)continue;
if(u==H){
ans=min(ans,cost);
continue;
}
for(auto [v,w]:adj[u]){
double now=cost+w;
if(arr[v]==0){
now=0;
if(now<d[v][0]){
d[v][0]=now;
pq.push({v,0,now});
}
}
else{
if(now<d[v][k]){
d[v][k]=now;
pq.push({v,k,now});
}
if(arr[v]==2 && k==0){
now*=pw;
if(now<d[v][k+1]){
d[v][k+1]=now;
pq.push({v,k+1,now});
}
}
}
}
}
if(ans==1e18)return -1;
else return 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... |