#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;
for (int u = 0; u < N; ++ u){
if (dp[u] == inf) continue;
if (arr[u] == 0) dp[u] = 0.0;
if (arr[u] == 2) dp[u] /= mid;
qu.push({-dp[u], u});
}
while (qu.size()){
auto [du, u] = qu.top();
qu.pop(); du = -du;
if (du != dp[u]) continue;
for (int id : adj[u]){
int v = x[id] ^ y[id] ^ u;
if (dp[v] > dp[u] + c[id]){
dp[v] = dp[u] + c[id];
qu.push({-dp[v], v});
}
}
}
ans = min(ans, dp[H]);
}
if (ans == inf) return -1;
return ans;
}
//
//int main(){
// 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);
//}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
600 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
568 KB |
Correct. |
2 |
Correct |
83 ms |
1576 KB |
Correct. |
3 |
Correct |
86 ms |
1360 KB |
Correct. |
4 |
Correct |
84 ms |
1620 KB |
Correct. |
5 |
Correct |
84 ms |
1616 KB |
Correct. |
6 |
Correct |
190 ms |
2632 KB |
Correct. |
7 |
Correct |
249 ms |
2520 KB |
Correct. |
8 |
Correct |
119 ms |
3564 KB |
Correct. |
9 |
Correct |
63 ms |
1408 KB |
Correct. |
10 |
Correct |
62 ms |
1360 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
93 ms |
560 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
199 ms |
7808 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
608 KB |
Correct. |
2 |
Correct |
43 ms |
1464 KB |
Correct. |
3 |
Correct |
46 ms |
1368 KB |
Correct. |
4 |
Correct |
100 ms |
2080 KB |
Correct. |
5 |
Correct |
35 ms |
1112 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
58 ms |
592 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
66 ms |
576 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
140 ms |
576 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |