#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
const double INF = 1E18;
struct node {
double di;
int u, k;
bool operator > (const node& o) const {
if (k != o.k) return k < o.k;
return di < o.di;
}
};
double solve(int32_t N, int32_t M, int32_t K, int32_t H, std::vector<int32_t> x, std::vector<int32_t> y, std::vector<int32_t> c, std::vector<int32_t> arr) {
K = min(K, 120);
vector<pair<int, int>> adj[N];
vector<vector<double>> d(N, vector<double> (K + 1, INF));
for (int i = 0; i < M; i++) {
if (x[i] != H) adj[x[i]].push_back({y[i], c[i]});
if (y[i] != H) adj[y[i]].push_back({x[i], c[i]});
}
queue<int> q;
vector<bool> vis(N, 0);
vis[0] = 1;
q.push(0);
while (!q.empty()) {
int u = q.front();
q.pop();
for (auto& [v, w] : adj[u]) {
if (!vis[v]) {
vis[v] = true;
q.push(v);
}
}
}
using T = node;
priority_queue<T, vector<T>, greater<T>> pq;
pq.push({0.0, 0, 0});
d[0][0] = 0.0;
for (int i = 0; i < N; i++) if (arr[i] == 0 && vis[i]) {
pq.push({0.0, i, 0});
d[i][0] = 0.0;
}
while (!pq.empty()) {
auto [di, u, k] = pq.top();
pq.pop();
if (di != d[u][k]) continue;
for (auto& [v, w] : adj[u]) {
double new_weight = d[u][k] + w;
if (d[v][k] > new_weight) {
d[v][k] = new_weight;
pq.push((node) {d[v][k], v, k});
}
if (arr[v] == 2 && k != K) {
double new_weight = d[u][k] + w;
new_weight /= 2.0;
if (d[v][k + 1] > new_weight) {
d[v][k + 1] = new_weight;
pq.push((node) {d[v][k + 1], v, k + 1});
}
}
}
}
double res = *min_element(d[H].begin(), d[H].end());
if (res >= INF) return -1;
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
468 KB |
Correct. |
2 |
Correct |
18 ms |
436 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
724 KB |
Correct. |
2 |
Correct |
25 ms |
704 KB |
Correct. |
3 |
Correct |
27 ms |
704 KB |
Correct. |
4 |
Correct |
25 ms |
712 KB |
Correct. |
5 |
Correct |
24 ms |
724 KB |
Correct. |
6 |
Correct |
22 ms |
3924 KB |
Correct. |
7 |
Correct |
26 ms |
3924 KB |
Correct. |
8 |
Correct |
16 ms |
7772 KB |
Correct. |
9 |
Correct |
23 ms |
408 KB |
Correct. |
10 |
Correct |
23 ms |
388 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
680 KB |
Correct. |
2 |
Correct |
25 ms |
748 KB |
Correct. |
3 |
Correct |
29 ms |
744 KB |
Correct. |
4 |
Correct |
31 ms |
416 KB |
Correct. |
5 |
Correct |
25 ms |
340 KB |
Correct. |
6 |
Correct |
6 ms |
3560 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3063 ms |
22428 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
124 ms |
716 KB |
Correct. |
2 |
Correct |
115 ms |
656 KB |
Correct. |
3 |
Correct |
123 ms |
684 KB |
Correct. |
4 |
Correct |
1100 ms |
3744 KB |
Correct. |
5 |
Correct |
30 ms |
400 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
732 KB |
Correct. |
2 |
Correct |
24 ms |
596 KB |
Correct. |
3 |
Correct |
44 ms |
29308 KB |
Correct. |
4 |
Correct |
36 ms |
2828 KB |
Correct. |
5 |
Correct |
24 ms |
404 KB |
Correct. |
6 |
Correct |
27 ms |
724 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3071 ms |
732 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3077 ms |
1088 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |