#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;
vector<vector<double>> dis(n, vector<double>((int)1e3 + 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 < (int)1e3 && (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);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
604 KB |
Correct. |
2 |
Correct |
31 ms |
584 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
114 ms |
8488 KB |
Correct. |
2 |
Correct |
151 ms |
8216 KB |
Correct. |
3 |
Correct |
136 ms |
8564 KB |
Correct. |
4 |
Correct |
141 ms |
8436 KB |
Correct. |
5 |
Correct |
135 ms |
8644 KB |
Correct. |
6 |
Correct |
129 ms |
78004 KB |
Correct. |
7 |
Correct |
169 ms |
76928 KB |
Correct. |
8 |
Correct |
71 ms |
156172 KB |
Correct. |
9 |
Correct |
108 ms |
1276 KB |
Correct. |
10 |
Correct |
126 ms |
1328 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
135 ms |
8296 KB |
Correct. |
2 |
Correct |
141 ms |
8696 KB |
Correct. |
3 |
Correct |
124 ms |
8392 KB |
Correct. |
4 |
Correct |
109 ms |
1268 KB |
Correct. |
5 |
Correct |
108 ms |
1504 KB |
Correct. |
6 |
Correct |
32 ms |
64336 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3078 ms |
529320 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
8176 KB |
Correct. |
2 |
Correct |
64 ms |
8016 KB |
Correct. |
3 |
Correct |
74 ms |
8048 KB |
Correct. |
4 |
Correct |
86 ms |
77500 KB |
Correct. |
5 |
Correct |
45 ms |
1292 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
8468 KB |
Correct. |
2 |
Correct |
51 ms |
7836 KB |
Correct. |
3 |
Correct |
26 ms |
7304 KB |
Correct. |
4 |
Correct |
45 ms |
46212 KB |
Correct. |
5 |
Correct |
56 ms |
1228 KB |
Correct. |
6 |
Correct |
68 ms |
8064 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3037 ms |
38212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3051 ms |
37276 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |