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 <iostream>
#include <vector>
#include <queue>
#include <limits>
using namespace std;
struct Node {
int country;
int passingTime;
Node(int c, int t) : country(c), passingTime(t) {}
bool operator>(const Node& other) const {
return passingTime > other.passingTime;
}
};
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
priority_queue<Node, vector<Node>, greater<Node>> pq;
vector<bool> visited(N, false);
pq.push(Node(0, 0));
while (!pq.empty()) {
Node current = pq.top();
pq.pop();
if (current.country == H) {
return current.passingTime;
}
visited[current.country] = true;
for (int i = 0; i < M; ++i) {
int neighbor;
int roadTime;
if (x[i] == current.country) {
neighbor = y[i];
roadTime = c[i];
} else if (y[i] == current.country) {
neighbor = x[i];
roadTime = c[i];
} else {
continue;
}
int passingTime = current.passingTime + roadTime;
if (arr[neighbor] == 2 && K > 0) {
passingTime /= 2;
K--;
} else if (arr[neighbor] == 0) {
passingTime = 0;
}
if (!visited[neighbor]) {
pq.push(Node(neighbor, passingTime));
}
}
}
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... |