#include <bits/stdc++.h>
#define all(v) ((v).begin(),(v).end())
#define F first
#define S second
typedef long long ll;
#define pii pair<ll,double>
using namespace std;
const ll mod = 1e9 + 7;
const ll mxN = 4e6 + 5;
struct path{
ll i,k,fl;
double val;
};
bool operator<(path a,path b){
return a.val < b.val;
}
bool operator>(path a,path b){
return a.val > b.val;
}
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
vector<vector<pii>>v;
const int nsz = N + 3;
const int ksz = K + 3;
double dp[nsz][ksz][2];
bool vis[nsz] = {};
v.resize(N + 3);
for(int i = 0;i < M;i++){
v[x[i]].push_back({y[i],(double)c[i]});
v[y[i]].push_back({x[i],(double)c[i]});
}
for(int i = 0;i < N;i++){
for(int j = 0;j <= K;j++){
dp[i][j][0] = (double)1e18;
dp[i][j][1] = (double)1e18;
}
}
dp[H][0][0] = 0;
priority_queue<path,vector<path>,greater<path>>q;
q.push({H,0,0});
while(q.size()){
auto u = q.top();
vis[u.i] = 1;
q.pop();
if(dp[u.i][u.k][u.fl] < u.val) continue;
for(auto x : v[u.i]){
if(u.fl == 1){
if(dp[x.F][u.k][1] > u.val){
dp[x.F][u.k][1] = u.val;
q.push({x.F,u.k,1,dp[x.F][u.k][1]});
}
}
else {
if(arr[u.i] == 0 && u.k < K){
if(dp[x.F][u.k + 1][1] > u.val){
dp[x.F][u.k + 1][1] = u.val;
q.push({x.F,u.k + 1,1,dp[x.F][u.k + 1][1]});
}
}
if(arr[u.i] == 2 && u.k < K){
if(dp[x.F][u.k + 1][0] > u.val + (x.S / (exp2(u.k + 1)))){
dp[x.F][u.k + 1][0] = u.val + (x.S / (exp2(u.k + 1)));
q.push({x.F,u.k + 1,u.fl,dp[x.F][u.k + 1][0]});
}
}
if(dp[x.F][u.k][0] > u.val + (x.S / (exp2(u.k)))){
dp[x.F][u.k][0] = u.val + (x.S / (exp2(u.k)));
q.push({x.F,u.k,u.fl,dp[x.F][u.k][0]});
}
}
}
}
if(!vis[0]) return -1;
double ans = (double)1e18;
for(int i = 0; i <= K;i++){
ans = min(ans,dp[0][i][0]);
ans = min(ans,dp[0][i][1]);
}
return ans;
}
// int main() {
// int T;
// assert(1 == scanf("%d", &T));
// while (T--){
// int N,M,K,H;
// assert(4 == scanf("%d %d %d\n%d", &N, &M, &K, &H));
// vector<int> x(M);
// vector<int> y(M);
// vector<int> c(M);
// vector<int> arr(N);
// for (int i=0;i<N;i++)
// assert(1 == scanf("%d", &arr[i]));
// for (int i=0;i<M;i++)
// assert(3 == scanf("%d %d %d", &x[i], &y[i], &c[i]));
// printf("%.12lf\n", solve(N, M, K, H, x, y, c, arr));
// }
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
604 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
1116 KB |
Correct. |
2 |
Correct |
24 ms |
1052 KB |
Correct. |
3 |
Correct |
22 ms |
1116 KB |
Correct. |
4 |
Correct |
23 ms |
860 KB |
Correct. |
5 |
Correct |
24 ms |
1096 KB |
Correct. |
6 |
Correct |
22 ms |
6560 KB |
Correct. |
7 |
Correct |
27 ms |
6304 KB |
Correct. |
8 |
Correct |
20 ms |
12636 KB |
Correct. |
9 |
Correct |
22 ms |
572 KB |
Correct. |
10 |
Correct |
25 ms |
348 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
856 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
576 ms |
36692 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
1112 KB |
Correct. |
2 |
Correct |
23 ms |
1112 KB |
Correct. |
3 |
Correct |
22 ms |
928 KB |
Correct. |
4 |
Correct |
23 ms |
6360 KB |
Correct. |
5 |
Correct |
20 ms |
348 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
24 ms |
1116 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
201 ms |
1180 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
979 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |