#include "cyberland.h"
#include <bits/stdc++.h>
const int MAX_N = 1e5 + 10;
const int MAX_K = 31;
typedef long double ld;
ld dist[2][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 < N; i ++) {
g[i].resize(0);
used[i] = false;
}
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[0][i][j] = dist[1][i][j] = 1e18;
}
}
dist[0][0][K] = 0;
for(int left = K; left >= 0; left --) {
std::priority_queue<std::pair<ld, int> > pq;
if(left != K) {
for(int i = 0; i < N; i ++) {
if((used[i] && arr[i] == 0) || i == 0) {
dist[0][i][left] = 0;
}
if(dist[0][i][left] < 1e17) {
pq.push({-dist[0][i][left], i});
}
if(dist[1][i][left] < 1e17) {
pq.push({-dist[1][i][left], i + MAX_N});
}
}
}
while(!pq.empty()) {
auto curr = pq.top(); pq.pop();
curr.first *= -1;
bool used = curr.second / MAX_N;
curr.second %= MAX_N;
if(curr.first > dist[used][curr.second][left]) {
continue;
}
if(curr.second == H) { continue; }
for(const auto &it : g[curr.second]) {
ld new_cost = curr.first + it.second / pw[left];
if(dist[0][it.first][left] > new_cost) {
dist[0][it.first][left] = new_cost;
pq.push({-new_cost, it.first});
}
}
}
for(int i = 0; i < N; i ++) {
if(arr[i] == 2) {
dist[1][i][left - 1] = dist[0][i][left];
}
}
}
ld ret = std::min(dist[0][H][0], dist[1][H][0]);
if(ret > 1e17) {
return -1;
}
return ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
46 ms |
2772 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
163 ms |
3720 KB |
Correct. |
2 |
Correct |
194 ms |
4756 KB |
Correct. |
3 |
Correct |
190 ms |
4808 KB |
Correct. |
4 |
Correct |
195 ms |
4736 KB |
Correct. |
5 |
Correct |
189 ms |
4812 KB |
Correct. |
6 |
Correct |
249 ms |
13804 KB |
Correct. |
7 |
Correct |
358 ms |
13924 KB |
Correct. |
8 |
Correct |
154 ms |
23664 KB |
Correct. |
9 |
Correct |
123 ms |
3696 KB |
Correct. |
10 |
Correct |
124 ms |
3696 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
245 ms |
3780 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1008 ms |
67712 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
112 ms |
3732 KB |
Correct. |
2 |
Correct |
121 ms |
4804 KB |
Correct. |
3 |
Correct |
127 ms |
4732 KB |
Correct. |
4 |
Correct |
187 ms |
13896 KB |
Correct. |
5 |
Correct |
79 ms |
3564 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
148 ms |
3828 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
205 ms |
3852 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
206 ms |
3752 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |