#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
//set.find_by_order(x) x-position value
//set.order_of_key(x) number of strictly less elements don't need *set.??
#define N 300005
#define wr cout << "Continue debugging\n";
#define all(x) (x).begin(), (x).end()
#define ll long long int
#define pii pair <int, int>
#define pb push_back
#define ff first
#define ss second
vector<pii> E[N];
void dfs(int nd, int h, vector<int> arr, priority_queue<pii> &q, vector<double> &dis, vector<bool> &vis){
if (!arr[nd]){
q.push({0, nd});
dis[nd] = 0;
}
vis[nd] = 1;
for (auto i : E[nd]){
if (vis[i.ff] or i.ff == h) continue;
dfs(i.ff, h, arr, q, dis, vis);
}
}
double solve(int n, int m, int k, int h, vector<int> x, vector<int> y, vector<int> c, vector<int> arr){
for (int i = 0; i < n; i++) E[i].clear();
for (int i = 0; i < m; i++){
E[x[i]].pb({y[i], c[i]});
E[y[i]].pb({x[i], c[i]});
}
vector<bool> vis(n+10, 0);
vector<double> dis(n+10, 1e18);
vector<int> cur(n+10, 0);
priority_queue<pii> q;
q.push({0, 0});
dis[0] = 0;
dfs(0, h, arr, q, dis, vis);
while(!q.empty()){
int x = q.top().ss;
q.pop();
if (x == h) continue;
for (auto i : E[x]){
int t=0;
double res = dis[x]+i.ss;
if (arr[i.ff] == 2){
if (cur[x] < k){res /= 2;t=1;}
}
if (dis[i.ff] > res){
dis[i.ff] = res;
cur[i.ff] = cur[x]+t;
q.push({-dis[i.ff], i.ff});
}
}
}
if (dis[h] == 1e18) return double(-1);
return dis[h];
}
// int main ()
// {
// int n, m, k, h;
// cin >> n >> m >> k >> h;
// vector<int> x(m), y(m), c(m), arr(n);
// for (int i = 0; i < m; i++){
// cin >> x[i] >> y[i] >> c[i];
// }
// for (int i = 0; i < n; i++) cin >> arr[i];
// cout << solve(n,m,k,h,x,y,c,arr);
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
7480 KB |
Correct. |
2 |
Correct |
17 ms |
7464 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
7624 KB |
Correct. |
2 |
Correct |
26 ms |
7604 KB |
Correct. |
3 |
Correct |
25 ms |
7520 KB |
Correct. |
4 |
Correct |
26 ms |
7568 KB |
Correct. |
5 |
Correct |
26 ms |
7548 KB |
Correct. |
6 |
Correct |
84 ms |
9108 KB |
Correct. |
7 |
Correct |
90 ms |
8936 KB |
Correct. |
8 |
Correct |
210 ms |
10608 KB |
Correct. |
9 |
Correct |
23 ms |
7380 KB |
Correct. |
10 |
Correct |
23 ms |
7436 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
7652 KB |
Correct. |
2 |
Correct |
28 ms |
7540 KB |
Correct. |
3 |
Correct |
35 ms |
7592 KB |
Correct. |
4 |
Correct |
25 ms |
7444 KB |
Correct. |
5 |
Correct |
25 ms |
7380 KB |
Correct. |
6 |
Correct |
17 ms |
8672 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
678 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
8548 KB |
Correct. |
2 |
Correct |
29 ms |
8496 KB |
Correct. |
3 |
Correct |
33 ms |
8552 KB |
Correct. |
4 |
Correct |
121 ms |
62636 KB |
Correct. |
5 |
Correct |
22 ms |
7572 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
8616 KB |
Correct. |
2 |
Correct |
25 ms |
8472 KB |
Correct. |
3 |
Correct |
39 ms |
13696 KB |
Correct. |
4 |
Correct |
69 ms |
64024 KB |
Correct. |
5 |
Correct |
23 ms |
7380 KB |
Correct. |
6 |
Correct |
27 ms |
8560 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
8584 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
8544 KB |
Correct. |
2 |
Correct |
13 ms |
9428 KB |
Correct. |
3 |
Runtime error |
664 ms |
2097152 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |