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;
typedef long double ld;
typedef tuple<ld, int, int> t3;
const int MAXN = 100005;
const ld inf = 1e18;
vector<pair<int, int>> adj[MAXN];
bool vis[MAXN], conn[MAXN];
ld dist[MAXN][70], pwr[70];
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr){
K = min(K, 68);
pwr[0] = 1;
for (int i = 1; i <= 68; i++) pwr[i] = pwr[i - 1] / 2;
for (int i = 0; i < N; i++){
adj[i].clear(); vis[i] = 0; conn[i] = 0;
for (int j = 0; j <= K; j++) dist[i][j] = inf;
}
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<int> q;
q.push(0); vis[0] = 1; conn[0] = 1;
while (!q.empty()){
int x = q.front(); q.pop();
if (x == H) continue;
if (arr[x] == 0) conn[x] = 1;
for (auto &[nn, nd] : adj[x])
if (!vis[nn]){
q.push(nn); vis[nn] = 1;
}
}
priority_queue<t3, vector<t3>, greater<t3>> pq;
pq.push({0, H, 0}); dist[H][0] = 0;
while (!pq.empty()){
ld d; int x, use; tie(d, x, use) = pq.top(); pq.pop();
if (dist[x][use] < d) continue;
if (conn[x]) return d;
for (auto &[nn, nd] : adj[x]){
ld fd = d + nd * pwr[use];
if (dist[nn][use] > fd){
dist[nn][use] = fd;
pq.push({dist[nn][use], nn, use});
}
if (arr[nn] == 2 && use < K && dist[nn][use + 1] > fd){
dist[nn][use + 1] = fd;
pq.push({dist[nn][use + 1], nn, use + 1});
}
}
}
return -1;
}
# | 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... |