#include "cyberland.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
struct node {
int i;
int k;
node(int a_i, int a_k): i(a_i), k(a_k) {};
int get_ind() {
return (i << 5) | k;
}
bool operator<(const node& other) const {
return true;
}
};
double solve(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr) {
vector<vector<pair<int, int>>> adj;
for(int i = 0; i < N; i++) {
vector<pair<int, int>> adj_row;
adj.push_back(adj_row);
}
for(int i = 0; i < M; i++) {
int curx = x[i], cury = y[i], curc = c[i];
adj[curx].push_back({cury, curc});
adj[cury].push_back({curx, curc});
}
/*
Idea: Dijkstra's algorithm
priority_queue<{total_time, node}>
*/
double ans = numeric_limits<double>::max();
priority_queue<pair<double, node>, vector<pair<double, node>>, greater<pair<double, node>>> q;
q.push({0.0, {0, 0}});
vector<bool> vis((N << 5) | K, false);
while(! q.empty()) {
auto [cur_time, cur_node] = q.top();
q.pop();
if(vis[cur_node.get_ind()]) continue;
vis[cur_node.get_ind()] = true;
auto [i, k] = cur_node;
if(i == H) {
ans = min(ans, cur_time);
continue;
}
for(auto [j, w] : adj[i]) {
q.push({(arr[j] == 0 ? 0.0 : cur_time + (double)w), {j, k}});
}
if(arr[i] == 2 && k <= K) {
for(auto [j, w] : adj[i]) {
q.push({cur_time / 2.0 + (double)w, {j, k + 1}});
}
}
}
if(ans < numeric_limits<double>::max()) {
return ans;
}
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
592 KB |
Correct. |
2 |
Correct |
22 ms |
856 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
600 KB |
Correct. |
2 |
Correct |
27 ms |
604 KB |
Correct. |
3 |
Correct |
26 ms |
600 KB |
Correct. |
4 |
Correct |
27 ms |
348 KB |
Correct. |
5 |
Correct |
27 ms |
604 KB |
Correct. |
6 |
Correct |
24 ms |
1504 KB |
Correct. |
7 |
Correct |
32 ms |
1452 KB |
Correct. |
8 |
Correct |
13 ms |
2528 KB |
Correct. |
9 |
Correct |
24 ms |
480 KB |
Correct. |
10 |
Correct |
24 ms |
496 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
27 ms |
348 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
94 ms |
5584 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
604 KB |
Correct. |
2 |
Correct |
26 ms |
604 KB |
Correct. |
3 |
Correct |
26 ms |
604 KB |
Correct. |
4 |
Correct |
30 ms |
1424 KB |
Correct. |
5 |
Correct |
24 ms |
612 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
25 ms |
600 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
495 ms |
2220 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
292 ms |
2868 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |