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 <bits/stdc++.h>
using namespace std;
#define pb push_back
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> a) {
vector<vector<pair<int,long double>>> g(n);
for(int i = 0;i < m;i++){
g[x[i]].pb({y[i],c[i]});
g[y[i]].pb({x[i],c[i]});
}
set<tuple<long double,int,int>> q;
q.insert({0,0,k});
long double dis[n][k + 1];
for(int i = 0;i < n;i++){
for(int j = 0;j <= k;j++){
dis[i][j] = 1e18;
}
}
dis[0][k] = 0;
while(!q.empty()){
auto [cost,v,nk] = *q.begin();q.erase(*q.begin());
//~ if(dis[v][nk] < cost) continue;
for(auto [to,w] : g[v]){
if(a[to] == 0){
if(dis[to][nk] > 0){
dis[to][nk] = 0;
q.insert({0,to,nk});
}
} else if(a[to] == 1){
if(dis[v][nk] + w < dis[to][nk]){
dis[to][nk] = dis[v][nk] + w;
q.insert({dis[to][nk],to,nk});
}
} else{
if(nk == 0){
if(dis[v][nk] + w < dis[to][nk]){
dis[to][nk] = dis[v][nk] + w;
q.insert({dis[to][nk],to,nk});
}
} else{
if((dis[v][nk] + w) / 2 < dis[to][nk - 1]){
dis[to][nk - 1] = (dis[v][nk] + w) / 2;
q.insert({dis[to][nk - 1],to,nk - 1});
}
}
}
}
}
long double ans = 1e18;
for(int i = 0;i <= k;i++){
ans = min(ans,dis[h][i]);
}
if(ans == 1e18) ans = -1;
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... |