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 <vector>
using namespace std;
#define vi vector<int>
#define pi pair<int,int>
#define x first
#define y second
#include "cyberland.h"
#define pd pair<double,double>
#define pdi pair<double,int>
#define vd vector<double>
#include <vector>
#include <queue>
void dfs(vector<bool>&vis, int i, int H,vector<vector<pdi>>&fr) {
if (i ==H)return;
if (vis[i])return;
vis[i] = 1;
for (pdi p : fr[i]) {
dfs(vis, p.y, H, fr);
}
}
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) {
K = min(K, 69);
vector<vd> dp(N, vd(K + 2,1e15));
vector<vector<pdi>> fr(N);
for (int i = 0; i < M; i++) {
fr[X[i]].push_back({ c[i],Y[i] });
fr[Y[i]].push_back({ c[i],X[i] });
}
priority_queue<pair<int,pdi>> pq;
vi fre;
vector<bool> vis(N);
dfs(vis, 0,H,fr);
pq.push({ 0,{0,0} });
for (int i = 0; i < N; i++)if (vis[i] == 1 && arr[i] == 0)pq.push({ 0,{0,i} });
while (!pq.empty()) {
pair<int, pdi> q = pq.top();
int s = q.x;
pdi p = q.y;
pq.pop();
if ((- s) > K)continue;
if (dp[p.y][-s] < -p.x)continue;
dp[p.y][-s] = -p.x;
if (p.y == H)continue;
for (pd f : fr[p.y]) {
if(arr[p.y]==2)pq.push({ s - 1,{p.x / 2 - f.x,f.y} });
if(f.x-p.x <= dp[f.y][-s])pq.push({ s,{p.x - f.x,f.y} });
}
}
double mini = 1e15;
for (int i = 0; i <= K; i++)mini = min(mini, dp[H][i]);
if(mini==1e15)return -1;
return mini;
}
# | 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... |