#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
const double INF = numeric_limits<double>::max();
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>>> g(N);
for (int i = 0; i < M; ++i) {
g[x[i]].emplace_back(y[i], c[i]);
g[y[i]].emplace_back(x[i], c[i]);
}
vector<int> kosh;
vector<bool> used(N), ot(N);
function<void(int, int)> dfs = [&](int v, int cnt) {
assert(!used[v]);
used[v] = true;
for (auto [to, weight]: g[v]) {
if (!used[to]) {
if (arr[to] == 2 && cnt) {
ot[to] = true;
kosh[to] = weight;
for (auto [to1, weight1]: g[to]) {
kosh[to] = min(kosh[to], weight1);
}
} else dfs(to, cnt);
}
}
};
vector<double> d(N + 1, INF);
d[0] = 0;
set<pair<double, int>> q;
q.emplace(d[0], 0);
while (!q.empty()) {
int nearest = q.begin()->second;
q.erase(q.begin());
for (auto [to, weight]: g[nearest]) {
double dis = d[nearest] + weight;
if (ot[to]) {
int cnt = K;
double ds = dis;
while (cnt--) dis = (dis + kosh[to] * 2) / 2;
dis = min(dis, ds);
}
if (!arr[to]) dis = 0;
if (d[to] > dis) {
q.erase(pair{d[to], to});
d[to] = dis;
q.emplace(d[to], to);
}
}
}
if (d[H] == INF) d[H] = -1;
return d[H];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
860 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
1372 KB |
Correct. |
2 |
Correct |
26 ms |
1472 KB |
Correct. |
3 |
Correct |
24 ms |
1552 KB |
Correct. |
4 |
Correct |
25 ms |
1628 KB |
Correct. |
5 |
Correct |
25 ms |
1628 KB |
Correct. |
6 |
Correct |
21 ms |
2208 KB |
Correct. |
7 |
Correct |
35 ms |
2236 KB |
Correct. |
8 |
Correct |
12 ms |
2904 KB |
Correct. |
9 |
Correct |
26 ms |
1372 KB |
Correct. |
10 |
Correct |
25 ms |
1360 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
26 ms |
1372 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
26 ms |
7256 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
1628 KB |
Correct. |
2 |
Correct |
23 ms |
1624 KB |
Correct. |
3 |
Correct |
22 ms |
1368 KB |
Correct. |
4 |
Correct |
22 ms |
2096 KB |
Correct. |
5 |
Correct |
20 ms |
1116 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
1368 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
24 ms |
1368 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
23 ms |
1372 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |