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 <vector>
#include <queue>
#include <algorithm>
using namespace std;
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
vector<double> min_time(N, numeric_limits<double>::infinity());
min_time[0] = 0;
// Custom comparator for the priority queue
auto cmp = [](const pair<double, int>& a, const pair<double, int>& b) {
return a.first > b.first;
};
priority_queue<pair<double, int>, vector<pair<double, int>>, decltype(cmp)> pq(cmp);
pq.push({0, 0});
while (!pq.empty()) {
double time = pq.top().first;
int country = pq.top().second;
pq.pop();
if (country == H) {
return time;
}
for (int i = 0; i < M; ++i) {
int neighbor;
if (x[i] == country) {
neighbor = y[i];
} else if (y[i] == country) {
neighbor = x[i];
} else {
continue;
}
double neighbor_time = time + c[i];
if (arr[neighbor] == 2 && K > 0) {
neighbor_time /= 2;
--K;
}
if (neighbor_time < min_time[neighbor]) {
min_time[neighbor] = neighbor_time;
pq.push({neighbor_time, neighbor});
}
}
}
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... |