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;
#define pid pair<int,double>
#define f first
#define s second
#define A pair<double, pair<int,int>>
vector<pid> adj[100005];
bool reach[100005];
int HH;
void dfs(int u) {
reach[u] = 1;
if(u==HH) return;
for(auto [v, w]:adj[u]) {
if(!reach[v]) dfs(v);
}
}
double mindis[100005][35];
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
HH = H;
for(int i=0;i<N;i++) {
adj[i].clear();
reach[i] = 0;
for(int j=0;j<=K;j++) {
mindis[i][j] = 1e18;
}
}
for(int i=0;i<M;i++) {
adj[x[i]].push_back({y[i], (double)c[i]});
adj[y[i]].push_back({x[i], (double)c[i]});
}
dfs(0);
if(!reach[H]) return -1;
priority_queue<A, vector<A>, greater<A>> pq;
pq.push({0, {0, 0}});
mindis[0][0] = 0;
for(int i=1;i<N;i++) {
if(reach[i] && arr[i]==0) {
pq.push({0, {i, 0}});
mindis[i][0] = 0;
}
}
while(!pq.empty()) {
double dis = pq.top().f;
auto [u, ct] = pq.top().s;
pq.pop();
if(mindis[u][ct]!=dis || u==H) continue;
for(auto [v, w]:adj[u]) {
if(arr[v]==1 && mindis[v][ct]>dis+w) {
mindis[v][ct] = dis+w;
pq.push({mindis[v][ct], {v, ct}});
} else if(arr[v]==2 && ct<K && mindis[v][ct+1]>(dis+w)/2) {
mindis[v][ct+1] = (dis+w)/2;
pq.push({mindis[v][ct+1], {v, ct+1}});
}
}
}
double ret = 1e18;
for(int i=0;i<=K;i++) ret = min(ret, mindis[H][i]);
return ret;
}
# | 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... |