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>
#include "cyberland.h"
//#define int long long
#define dp dist
using namespace std;
const int K = 31;
const int N = 100010;
vector <pair <int, int>> g[N];
double dist[N][K][2];
int op[N];
double solve(int32_t n, int32_t m, int32_t k, int32_t h, std::vector<int32_t> x, std::vector<int32_t> y, std::vector<int32_t> c, std::vector<int32_t> arr) {
k = min(k, K);
for(int i = 0;i < n;i++){
g[i].clear();
}
for(int i = 0;i < m;i++){
int a = x[i], b = y[i], w = c[i];
g[a].push_back({b, w});
g[b].push_back({a, w});
}
for(int i = 0;i < n;i++){
op[i] = arr[i];
}
for(int i = 0;i < n;i++){
for(int j = 0;j <= k;j++){
dist[i][j][0] = dist[i][j][1] = 1e18;
}
}
priority_queue <pair <double, array <int, 3>>> pq;
for(int i = 0;i <= k;i++){
dist[0][i][0] = 0;
pq.push({0, {0, i, 0}});
}
while(!pq.empty()){
auto [d,cu] = pq.top();
auto [v, i, flag] = cu;
pq.pop();
d *= -1;
if(d != dist[v][i][flag]) continue;
if(v == h) continue;
if(flag == 0){
if(op[v] == 0){
if(dist[v][i][1] > 0){
dist[v][i][1] = 0;
pq.push({-dist[v][i][1], {v, i, 1}});
}
}
else if(op[v] == 2){
if(i > 0){
if(dist[v][i-1][1] > (dist[v][i][0])/(2.0)){
dist[v][i-1][1] = (dist[v][i][0])/(2.0);
pq.push({-dist[v][i-1][1], {v, i-1, 1}});
}
}
}
}
for(auto [x, w] : g[v]){
if(dist[v][i][flag]+w < dist[x][i][0]){
dist[x][i][0] = dist[v][i][flag]+w;
pq.push({-dist[x][i][0], {x, i, 0}});
}
}
}
double res = 1e18;
for(int i = 0;i <= k;i++){
res = min(res, dp[h][i][0]);
}
return (res == 1e18 ? -1 : res);
}
# | 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... |