#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<long long, long long>
#define fr first
#define se second
const double INF = 1e100;
vector<vector<pii>> adj;
vector<bool> vis;
void dfs(int node) {
if (vis[node]) return;
vis[node] = 1;
for (auto u : adj[node]) dfs(u.fr);
}
double solve(int32_t n, int32_t m, int32_t k, int32_t h, vector<int32_t> x, vector<int32_t> y, vector<int32_t> c, vector<int32_t> arr) {
adj.clear();
vis.clear();
adj.resize(n);
vis.resize(n);
for (int i = 0; i < m; i++) {
int a = x[i], b = y[i], co = c[i];
if (a != h) adj[a].push_back({b, co});
if (b != h) adj[b].push_back({a, co});
}
vector<vector<bool>> prop(n, vector<bool>(31));
vector<vector<double>> dist(n, vector<double>(31, INF));
priority_queue<pair<double, pii>> pq;
dist[0][0] = 0;
pq.push({0, {0, 0}});
dfs(0);
for (int i = 0; i < n; i++) {
if ((arr[i] == 0) && vis[i]) {
dist[i][0] = 0;
pq.push({0, {i, 0}});
}
}
while (!pq.empty()) {
auto [u, qtd] = pq.top().se;
pq.pop();
if (prop[u][qtd]) continue;
prop[u][qtd] = 1;
for (auto [v, cost] : adj[u]) {
// propaga sem aumentar o k
if (!prop[v][qtd]) {
double novo = (((double)cost) + dist[u][qtd]);
//if (arr[v] == 0) novo = 0;
if (novo < dist[v][qtd]) {
dist[v][qtd] = novo;
pq.push({-novo, {v, qtd}});
}
}
if ((qtd < k) && (arr[v] == 2) && (!prop[v][qtd + 1])) {
double novo = (((double)cost) + dist[u][qtd]) / 2.0;
if (novo < dist[v][qtd + 1]) {
dist[v][qtd + 1] = novo;
pq.push({-novo, {v, qtd + 1}});
}
}
}
}
double ans = INF;
for (int i = 0; i <= k; i++) {
ans = min(ans, dist[h][i]);
}
if (ans == INF) return -1;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
592 KB |
Correct. |
2 |
Correct |
19 ms |
460 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
848 KB |
Correct. |
2 |
Correct |
33 ms |
988 KB |
Correct. |
3 |
Correct |
28 ms |
908 KB |
Correct. |
4 |
Correct |
31 ms |
916 KB |
Correct. |
5 |
Correct |
32 ms |
948 KB |
Correct. |
6 |
Correct |
33 ms |
4880 KB |
Correct. |
7 |
Correct |
36 ms |
4844 KB |
Correct. |
8 |
Correct |
20 ms |
9296 KB |
Correct. |
9 |
Correct |
28 ms |
504 KB |
Correct. |
10 |
Correct |
26 ms |
336 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
876 KB |
Correct. |
2 |
Correct |
37 ms |
1876 KB |
Correct. |
3 |
Correct |
27 ms |
1868 KB |
Correct. |
4 |
Correct |
30 ms |
1360 KB |
Correct. |
5 |
Correct |
30 ms |
1428 KB |
Correct. |
6 |
Correct |
8 ms |
4432 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
154 ms |
30396 KB |
Correct. |
2 |
Incorrect |
144 ms |
2156 KB |
Wrong Answer. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
872 KB |
Correct. |
2 |
Correct |
30 ms |
848 KB |
Correct. |
3 |
Correct |
28 ms |
892 KB |
Correct. |
4 |
Correct |
30 ms |
4524 KB |
Correct. |
5 |
Correct |
26 ms |
336 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
924 KB |
Correct. |
2 |
Correct |
31 ms |
1756 KB |
Correct. |
3 |
Correct |
63 ms |
36436 KB |
Correct. |
4 |
Correct |
24 ms |
4000 KB |
Correct. |
5 |
Correct |
31 ms |
1360 KB |
Correct. |
6 |
Correct |
32 ms |
1840 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
180 ms |
1472 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
848 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |