#include <bits/stdc++.h>
#include "cyberland.h"
// #include "stub.cpp"
using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
double solve(int n, int M, int K, int H, vector<int> X, vector<int> Y, vector<int> C, vector<int> a) {
vector<pii> E[n];
for (int i = 0; i < M; i++) {
E[X[i]].push_back({Y[i], C[i]});
E[Y[i]].push_back({X[i], C[i]});
}
queue<int> q;
vector<bool> vis0(n);
q.push(0); vis0[0] = true;
while (!q.empty()) {
int x = q.front(); q.pop();
if (x == H) continue;
for (auto [i, w] : E[x]) {
if (!vis0[i]) {
q.push(i);
vis0[i] = true;
}
}
}
if (!vis0[H]) return -1;
K = min(K, (int)1e2);
vector<vector<double>> dis(n, vector<double>(K + 1, 1e18));
priority_queue<pair<double, pii>> pq;
for (int i = 0; i < n; i++) {
if (!i || (!a[i] && vis0[i])) {
dis[i][0] = 0;
pq.push({0, {i, 0}});
}
}
while (!pq.empty()) {
double d = pq.top().ff; d = -d;
auto [x, y] = pq.top().ss; pq.pop();
if (d != dis[x][y]) continue;
if (x == H) return d;
for (auto [i, w] : E[x]) {
if (!a[i]) continue;
if (d + w < dis[i][y]) {
dis[i][y] = d + w;
pq.push({-dis[i][y], {i, y}});
}
if (a[i] == 2 && y < K && (d + w) / 2 < dis[i][y + 1]) {
dis[i][y + 1] = (d + w) / 2;
pq.push({-dis[i][y + 1], {i, y + 1}});
}
}
}
assert(false);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
604 KB |
Correct. |
2 |
Correct |
13 ms |
604 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
860 KB |
Correct. |
2 |
Correct |
21 ms |
848 KB |
Correct. |
3 |
Correct |
19 ms |
820 KB |
Correct. |
4 |
Correct |
20 ms |
800 KB |
Correct. |
5 |
Correct |
19 ms |
856 KB |
Correct. |
6 |
Correct |
19 ms |
3952 KB |
Correct. |
7 |
Correct |
30 ms |
3928 KB |
Correct. |
8 |
Correct |
12 ms |
7512 KB |
Correct. |
9 |
Correct |
18 ms |
520 KB |
Correct. |
10 |
Correct |
18 ms |
600 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
604 KB |
Correct. |
2 |
Correct |
38 ms |
764 KB |
Correct. |
3 |
Correct |
20 ms |
860 KB |
Correct. |
4 |
Correct |
21 ms |
344 KB |
Correct. |
5 |
Correct |
20 ms |
544 KB |
Correct. |
6 |
Correct |
5 ms |
3420 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
108 ms |
23560 KB |
Correct. |
2 |
Incorrect |
114 ms |
972 KB |
Wrong Answer. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
752 KB |
Correct. |
2 |
Correct |
21 ms |
604 KB |
Correct. |
3 |
Correct |
21 ms |
736 KB |
Correct. |
4 |
Correct |
18 ms |
3596 KB |
Correct. |
5 |
Correct |
17 ms |
532 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
864 KB |
Correct. |
2 |
Correct |
16 ms |
812 KB |
Correct. |
3 |
Correct |
30 ms |
7364 KB |
Correct. |
4 |
Correct |
15 ms |
2652 KB |
Correct. |
5 |
Correct |
19 ms |
536 KB |
Correct. |
6 |
Correct |
19 ms |
824 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
91 ms |
1120 KB |
Correct. |
2 |
Correct |
14 ms |
1472 KB |
Correct. |
3 |
Incorrect |
45 ms |
26240 KB |
Wrong Answer. |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
463 ms |
4536 KB |
Correct. |
2 |
Correct |
76 ms |
8228 KB |
Correct. |
3 |
Correct |
62 ms |
91216 KB |
Correct. |
4 |
Incorrect |
119 ms |
4800 KB |
Wrong Answer. |
5 |
Halted |
0 ms |
0 KB |
- |