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 <vector>
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<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]});
}
queue<pair<int,int>>q;
q.push({0,K});
vector<vector<double> >dist(N,vector<double>(K + 1,1e12));
dist[0][K] = 0;
while(!q.empty()){
auto u = q.front();
q.pop();
if (u.first == H)continue;
for (auto x:adj[u.first]){
long long v = x.second;
if (arr[x.first] == 0) v = -dist[u.first][u.second];
if (dist[x.first][u.second] > dist[u.first][u.second] + v){
dist[x.first][u.second] = dist[u.first][u.second] + v;
q.push({x.first,u.second});
}
if (arr[x.first] == 2 && u.second > 0){
if (dist[x.first][u.second - 1] > (dist[u.first][u.second] + x.second)/2){
dist[x.first][u.second - 1] = (dist[u.first][u.second] + x.second)/2;
q.push({x.first,u.second - 1});
}
}
}
}
double ans = 1e12;
for (int i = 0;i<=K;++i) ans = min(ans,dist[H][i]);
if (ans == 1e12) return -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... |