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 int long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
const int maxn = 1e5+10;
const int inf = 1e18+10;
int n, m, k, a[maxn], h, mark[maxn];
vector<pair<int,int>> g[maxn];
double d[maxn][35];
void dfs(int u) {
mark[u] = 1;
if(u == h) return;
for(auto v : g[u]) {
if(mark[v.fr] == 0) dfs(v.fr);
}
}
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) {
n = N;
m = M;
k = K;
h = H;
for(int i = 0; i < n; i++) {
g[i].clear();
mark[i] = 0;
a[i] = arr[i];
}
for(int i = 0; i < m; i++) {
g[x[i]].pb(mp(y[i],c[i]));
g[y[i]].pb(mp(x[i],c[i]));
}
dfs(0);
for(int i = 0; i < n; i++) {
for(int j = 0; j <= k; j++) {
d[i][j] = inf;
}
}
priority_queue<pair<double,pair<int,int>>> pq;
d[0][0] = 0;
pq.push(mp(0,mp(0,0)));
for(int i = 1; i < n; i++) {
if(a[i] == 0 && mark[i]) {
d[i][0] = 0;
pq.push(mp(0,mp(i,0)));
}
}
while(pq.size()) {
int u = pq.top().sc.fr;
int j = pq.top().sc.sc;
double dist = -pq.top().fr;
pq.pop();
if(d[u][j] != dist) continue;
if(u == h) continue;
for(auto V : g[u]) {
int v = V.fr;
int w = V.sc;
if(d[v][j] > d[u][j]+w) {
d[v][j] = d[u][j]+w;
pq.push(mp(-d[v][j],mp(v,j)));
}
if(a[v] == 2 && j != k && d[v][j+1] > (d[u][j]+w)/((double) 2.0)) {
d[v][j+1] = (d[u][j]+w)/((double)2.0);
pq.push(mp(-d[v][j+1],mp(v,j+1)));
}
}
}
double ans = inf;
for(int i = 0; i <= k; i++) {
ans = min(ans, d[h][i]);
}
if(ans == inf) 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... |