#include "cyberland.h"
#include <bits/stdc++.h>
const int MAX_N = 1e5 + 10;
const int MAX_K = 31;
typedef long double ld;
ld dist[MAX_N][MAX_K];
std::vector<std::pair<int, int> > g[MAX_N];
bool used[MAX_N];
void dfs(int x) {
if(used[x]) { return; }
used[x] = true;
for(const auto &it : g[x]) {
dfs(it.first);
}
}
ld pw[MAX_K];
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) {
for(int i = 0; i < M; i ++) {
g[x[i]].push_back({y[i], c[i]});
g[y[i]].push_back({x[i], c[i]});
}
dfs(0);
K = std::min(K, MAX_K - 1);
pw[0] = 1;
for(int i = 1; i <= K; i ++) {
pw[i] = (pw[i - 1] * 2.0);
}
for(int i = 0; i < N; i ++) {
for(int j = 0; j <= K; j ++) {
dist[i][j] = 1e18;
}
}
std::priority_queue<std::pair<ld, std::pair<int, int> > > pq;
for(int i = 0; i < N; i ++) {
if(arr[i] == 0 || i == 0) {
for(int j = 0; j <= K - (int)(i != 0); j ++) {
dist[i][j] = 0;
pq.push({0, {i, j}});
}
}
}
while(!pq.empty()) {
auto curr = pq.top(); pq.pop();
curr.first *= -1;
if(curr.first > dist[curr.second.first][curr.second.second]) {
continue;
}
for(const auto &it : g[curr.second.first]) {
ld new_dist = curr.first + it.second / pw[curr.second.second];
if(new_dist < dist[it.first][curr.second.second]) {
dist[it.first][curr.second.second] = new_dist;
pq.push({-new_dist, {it.first, curr.second.second}});
}
if(arr[it.first] == 2 && curr.second.first > 0) {
if(new_dist < dist[it.first][curr.second.second - 1]) {
dist[it.first][curr.second.second - 1] = new_dist;
pq.push({-new_dist, {it.first, curr.second.second - 1}});
}
}
}
}
return dist[N - 1][0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3054 ms |
2912 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1729 ms |
5812 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1762 ms |
8188 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1095 ms |
68836 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1739 ms |
5360 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1691 ms |
8488 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2193 ms |
10932 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2191 ms |
11468 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |