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"
using namespace std;
#include <vector>
/* void bfs(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr, vector<pair<int, double>> adj[], double dist[]) { */
/* } */
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, 70);
vector<pair<int, double>> adj[N];
for(int i = 0; i < M; ++i) {
adj[x[i]].emplace_back(y[i], c[i]);
adj[y[i]].emplace_back(x[i], c[i]);
}
double dist[N][K];
for(int i = 0; i < N; ++i) {
for(int j = 0; j < K; ++j) {
dist[i][j] = -1;
}
}
if(1) { // BFS starts
bool vis[N] = {};
queue<int> qu;
vis[0] = 1;
qu.push(0);
dist[0][0] = 0;
while(!qu.empty()) {
int a = qu.front();
qu.pop();
if(a == H) continue;
for(auto [b, w] : adj[a]) {
if(vis[b]) continue;
vis[b] = 1;
qu.push(b);
if(arr[b] == 0) dist[b][0] = 0;
}
}
} // BFS ends
priority_queue<pair<double, pair<int, int>>> pq;
for(int i = 0; i < N; ++i) {
if(dist[i][0] == 0) {
pq.push({-dist[i][0], {-(double)0, i}});
}
}
while(!pq.empty()) {
int a = pq.top().second.second;
int st = pq.top().second.first;
double d = -pq.top().first;
pq.pop();
if(dist[a][st] < d || a == H) {
continue;
}
for(auto [b, w] : adj[a]) {
if(dist[b][st] == -1 || d + w < dist[b][st]) {
dist[b][st] = d + w;
pq.push({-dist[b][st], {-st, b}});
}
if(arr[b] == 2 && st < K - 1) {
++st;
if(dist[b][st] == -1 || (d + w) / 2 < dist[b][st]) {
dist[b][st] = (d + w) / 2;
pq.push({-dist[b][st], {-st, b}});
}
}
}
}
double ans = -1;
for(int i = 0; i < K; ++i) {
if(ans == -1 || (dist[H][i] != -1 && ans > dist[H][i]))
ans = dist[H][i];
}
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... |