#include <bits/stdc++.h>
#define db double
using namespace std;
const db inf = 1e12;
const db mid = 2.0;
db solve(int N, int M, int K, int H, vector <int> x, vector <int> y, vector <int> c, vector <int> arr){
K = min(K, 100);
vector <vector <int>> adj(N);
for (int i = 0; i < M; ++ i) adj[x[i]].push_back(i), adj[y[i]].push_back(i);
vector <db> dp(N, inf);
dp[0] = 0.0; db ans = inf;
for (int loops = 0; loops <= K; ++ loops){
priority_queue <pair <db, int>> qu;
vector <db> rd(N, inf);
for (int u = 0; u < N; ++ u){
if (dp[u] == inf || (u > 0 && arr[u] == 1)) continue;
if (arr[u] == 0) rd[u] = 0.0;
qu.push({-dp[u] / mid, u});
}
while (qu.size()){
auto [du, u] = qu.top();
qu.pop(); du = -du;
if (u == H) continue;
for (int id : adj[u]){
int v = x[id] ^ y[id] ^ u;
if (rd[v] > du + c[id]){
rd[v] = du + c[id];
qu.push({-rd[v], v});
}
}
}
if (!loops && rd[H] == inf) break;
dp = rd;
ans = min(ans, dp[H]);
}
if (ans == inf) return -1;
return ans;
}
//void solve(){
// int N, M, K; cin >> N >> M >> K;
// int H; cin >> H;
// vector <int> arr(N); for (int i = 0; i < N; ++ i) cin >> arr[i];
// vector <int> x(M), y(M), z(M); for (int i = 0; i < M; ++ i) cin >> x[i] >> y[i] >> z[i];
// cout << fixed << setprecision(10) << solve(N, M, K, H, x, y, z, arr) << '\n';
//}
//
//int main(){
// freopen("cyberland.inp", "r", stdin);
// freopen("cyberland.out", "w", stdout);
//// ios_base::sync_with_stdio(0);
//// cin.tie(0);
//// cout.tie(0);
//
// int t = 1;
// while (t --) solve();
//
// return 0;
//}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
508 KB |
Correct. |
2 |
Correct |
22 ms |
812 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
592 KB |
Correct. |
2 |
Correct |
69 ms |
596 KB |
Correct. |
3 |
Correct |
65 ms |
560 KB |
Correct. |
4 |
Correct |
67 ms |
348 KB |
Correct. |
5 |
Correct |
66 ms |
596 KB |
Correct. |
6 |
Correct |
142 ms |
1416 KB |
Correct. |
7 |
Correct |
185 ms |
1408 KB |
Correct. |
8 |
Correct |
90 ms |
2548 KB |
Correct. |
9 |
Correct |
54 ms |
532 KB |
Correct. |
10 |
Correct |
53 ms |
520 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
572 KB |
Correct. |
2 |
Correct |
92 ms |
1364 KB |
Correct. |
3 |
Correct |
84 ms |
1332 KB |
Correct. |
4 |
Correct |
79 ms |
1360 KB |
Correct. |
5 |
Correct |
71 ms |
1360 KB |
Correct. |
6 |
Correct |
38 ms |
1368 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
6232 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
592 KB |
Correct. |
2 |
Correct |
43 ms |
344 KB |
Correct. |
3 |
Correct |
47 ms |
520 KB |
Correct. |
4 |
Correct |
109 ms |
1364 KB |
Correct. |
5 |
Correct |
37 ms |
348 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
600 KB |
Correct. |
2 |
Correct |
41 ms |
1292 KB |
Correct. |
3 |
Correct |
27 ms |
9812 KB |
Correct. |
4 |
Correct |
65 ms |
1784 KB |
Correct. |
5 |
Correct |
42 ms |
1364 KB |
Correct. |
6 |
Correct |
48 ms |
1336 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
592 KB |
Correct. |
2 |
Correct |
16 ms |
604 KB |
Correct. |
3 |
Incorrect |
310 ms |
12660 KB |
Wrong Answer. |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
192 ms |
584 KB |
Correct. |
2 |
Correct |
43 ms |
604 KB |
Correct. |
3 |
Incorrect |
29 ms |
13148 KB |
Wrong Answer. |
4 |
Halted |
0 ms |
0 KB |
- |