#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 {
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, min(N, 90));
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;
}
for (int i = 1; i <= K; i++) {
while (!pq.empty()) {
auto [di, u, k] = pq.top();
pq.pop();
if (di != d[u][k]) continue;
for (auto& [v, w] : adj[u]) {
if (arr[v] == 0 || arr[v] == 2) continue;
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});
}
}
}
for (int j = 0; j < N; j++) if (vis[j]) pq.push({d[j][i - 1], j, i - 1});
while (!pq.empty()) {
auto [di, u, k] = pq.top();
pq.pop();
if (di != d[u][k] || k >= i) continue;
for (auto& [v, w] : adj[u]) {
if (arr[v] == 0 || arr[v] == 1) continue;
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});
}
}
}
}
for (int j = 0; j < N; j++) if (vis[j]) pq.push({d[j][i], j, i});
}
// for (int i = 0; i <= H; i++) {
// for (int j = 0; j <= K; j++) {
// cout << i << " " << j << " ";
// cout << fixed << setprecision(6) << d[i][j] << "\n";
// }
// }
double res = *min_element(d[H].begin(), d[H].end());
if (res >= INF) return -1;
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
468 KB |
Correct. |
2 |
Correct |
18 ms |
468 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
131 ms |
736 KB |
Correct. |
2 |
Correct |
163 ms |
824 KB |
Correct. |
3 |
Correct |
149 ms |
724 KB |
Correct. |
4 |
Correct |
159 ms |
720 KB |
Correct. |
5 |
Correct |
154 ms |
732 KB |
Correct. |
6 |
Correct |
160 ms |
4588 KB |
Correct. |
7 |
Correct |
219 ms |
4432 KB |
Correct. |
8 |
Correct |
114 ms |
8664 KB |
Correct. |
9 |
Correct |
122 ms |
388 KB |
Correct. |
10 |
Correct |
122 ms |
524 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
157 ms |
688 KB |
Correct. |
2 |
Correct |
154 ms |
724 KB |
Correct. |
3 |
Correct |
143 ms |
768 KB |
Correct. |
4 |
Correct |
128 ms |
384 KB |
Correct. |
5 |
Correct |
120 ms |
400 KB |
Correct. |
6 |
Correct |
36 ms |
3608 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
192 ms |
22668 KB |
Correct. |
2 |
Incorrect |
228 ms |
724 KB |
Wrong Answer. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
159 ms |
684 KB |
Correct. |
2 |
Correct |
159 ms |
672 KB |
Correct. |
3 |
Correct |
179 ms |
744 KB |
Correct. |
4 |
Correct |
1101 ms |
4064 KB |
Correct. |
5 |
Correct |
67 ms |
340 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
102 ms |
720 KB |
Correct. |
2 |
Correct |
71 ms |
708 KB |
Correct. |
3 |
Correct |
47 ms |
29236 KB |
Correct. |
4 |
Correct |
89 ms |
2928 KB |
Correct. |
5 |
Correct |
69 ms |
384 KB |
Correct. |
6 |
Correct |
83 ms |
724 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
298 ms |
632 KB |
Correct. |
2 |
Correct |
57 ms |
980 KB |
Correct. |
3 |
Execution timed out |
3031 ms |
29836 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
827 ms |
1140 KB |
Correct. |
2 |
Correct |
161 ms |
1748 KB |
Correct. |
3 |
Correct |
2740 ms |
90516 KB |
Correct. |
4 |
Execution timed out |
3069 ms |
5532 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |