이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <vector>
#include <queue>
#include <limits>
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) {
// Initialize the graph
vector<vector<pair<int, int>>> graph(N);
for (int i = 0; i < M; ++i) {
graph[x[i]].push_back({y[i], c[i]});
graph[y[i]].push_back({x[i], c[i]});
}
// Initialize distances
vector<double> dist(N, numeric_limits<double>::max());
dist[0] = 0; // Distance from your country to itself is 0
// Priority queue to store {distance, country} pairs
priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> pq;
pq.push({0, 0}); // Start from your country
while (!pq.empty()) {
int u = pq.top().second;
double d = pq.top().first;
pq.pop();
// Check if we have reached Cyberland
if (u == H) return d;
// Check if we have used up all divide-by-2 abilities
int remaining_divide_by_2 = K;
if (arr[u] == 2) remaining_divide_by_2--;
for (auto& edge : graph[u]) {
int v = edge.first;
int cost = edge.second;
double new_dist = d + cost;
// Apply special ability of the country
if (arr[v] == 0) new_dist = d; // Passing time becomes 0
else if (arr[v] == 2 && remaining_divide_by_2 > 0) { // Divide-by-2 ability
new_dist = d + cost / 2.0;
remaining_divide_by_2--;
}
// Update the distance if the new path is shorter
if (new_dist < dist[v]) {
dist[v] = new_dist;
pq.push({new_dist, v});
}
}
}
// If Cyberland is unreachable
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... |