#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
716 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
1088 KB |
Correct. |
2 |
Correct |
29 ms |
1292 KB |
Correct. |
3 |
Correct |
26 ms |
1112 KB |
Correct. |
4 |
Correct |
28 ms |
1056 KB |
Correct. |
5 |
Correct |
27 ms |
1124 KB |
Correct. |
6 |
Correct |
49 ms |
1468 KB |
Correct. |
7 |
Correct |
143 ms |
1272 KB |
Correct. |
8 |
Correct |
215 ms |
1688 KB |
Correct. |
9 |
Correct |
15 ms |
1112 KB |
Correct. |
10 |
Correct |
15 ms |
1116 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
31 ms |
1108 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
584 ms |
3764 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
1112 KB |
Correct. |
2 |
Correct |
20 ms |
1116 KB |
Correct. |
3 |
Correct |
22 ms |
1112 KB |
Correct. |
4 |
Correct |
71 ms |
1240 KB |
Correct. |
5 |
Correct |
13 ms |
1116 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
21 ms |
1184 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
23 ms |
1372 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
208 ms |
1680 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |