#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N = 1e5+5;
const ll INF = 1e15; // 1e5*1e9=1e14
vector<pii> adj[N];
ll d[N];
double asd = INF;
void dfs(int x, int pr, double sm, int h, int k, vector<int> &arr){
if(x == h){
umin(asd, sm);
return;
}
for(auto [i, val] : adj[x])
if(i != pr and i){
double taze = sm+val;
if(!arr[i])
taze = 0;
else if(arr[i] == 2 and k)
taze /= 2;
dfs(i, x, taze, h, k, arr);
}
}
double solve(int n, int m, int k, int h, vector<int> u, vector<int> v, vector<int> w, vector<int> arr){
for(int i = 0; i < m; ++i){
adj[u[i]].pb({v[i], w[i]});
adj[v[i]].pb({u[i], w[i]});
}
if(n <= 3){
asd = INF;
dfs(0, -1, 0, h, k, arr);
if(asd == INF)
asd = -1;
for(int i = 0; i <= n; ++i)
adj[i].clear();
return asd;
}
for(int i = 0; i <= n; ++i)
d[i] = INF;
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
pq.push({0, 0});
d[0] = 0;
while(!pq.empty()){
int x = pq.top().ss;
pq.pop();
for(auto it = adj[x].begin(); it != adj[x].end(); ++it){
int i = (*it).ff, val = (*it).ss;
if(umin(d[i], d[x]+val))
pq.push({d[i], i});
}
}
for(int i = 0; i <= n; ++i)
adj[i].clear();
if(d[h] == INF)
d[h] = -1;
double answer = 0;
answer += d[h];
return answer;
}
// int main(){
// double kk = solve(5, 4, 10, 3, {0, 0, 2, 2}, {1, 2, 3, 4}, {6, 5, 7, 8}, {1, 1, 1, 1, 1});
// printf("%f\n", kk);
// return 0;
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
3420 KB |
Correct. |
2 |
Correct |
13 ms |
3688 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
3576 KB |
Correct. |
2 |
Correct |
16 ms |
3416 KB |
Correct. |
3 |
Correct |
16 ms |
3516 KB |
Correct. |
4 |
Correct |
17 ms |
3528 KB |
Correct. |
5 |
Correct |
15 ms |
3516 KB |
Correct. |
6 |
Correct |
14 ms |
4188 KB |
Correct. |
7 |
Correct |
19 ms |
4184 KB |
Correct. |
8 |
Correct |
9 ms |
4956 KB |
Correct. |
9 |
Correct |
17 ms |
3460 KB |
Correct. |
10 |
Correct |
17 ms |
3452 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
3420 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
22 ms |
7004 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
3420 KB |
Correct. |
2 |
Correct |
21 ms |
3420 KB |
Correct. |
3 |
Correct |
27 ms |
3420 KB |
Correct. |
4 |
Correct |
18 ms |
4188 KB |
Correct. |
5 |
Correct |
24 ms |
3444 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
3416 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
3420 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
3584 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |