#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 pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#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 = 2e5+5;
const int K = 70;
vector<pair<int, double>> adj[N];
bool vis0[N], vis[N][K];
priority_queue<tuple<int, double, int>, vector<tuple<int, double, int>>, greater<tuple<int, double, int>>> q;
vector<int> ad;
void dfs(int x){
if(vis0[x])
return;
vis0[x] = 1;
if(ad[x] == 0)
q.push({0, 0, x});
for(auto [i, w] : adj[x])
dfs(i);
}
double solve(int n, int m, int k, int h, vector<int> u, vector<int> v, vector<int> w, vector<int> arr){
umin(k, 70);
ad.clear();
for(auto &i : arr)
ad.pb(i);
memset(vis0, 0, sizeof vis0);
for(int i = 0; i <= n; ++i)
adj[i].clear();
while(!q.empty())
q.pop();
ad[0] = 0;
vis0[h] = 1;
for(int i = 0; i < m; ++i){
adj[u[i]].pb({v[i], w[i]});
adj[v[i]].pb({u[i], w[i]});
}
double answer = 1e18;
dfs(0);
memset(vis, 0, sizeof vis);
while(!q.empty()){
auto [x0, w0, x] = q.top();
q.pop();
if(x == h){
umin(answer, w0);
continue;
}
if(vis[x][x0])
continue;
vis[x][x0] = 1;
for(auto &[i, w] : adj[x]){
if(!vis[i][x0])
q.push({x0, w0+w, i});
if(ad[i] == 2 and x0 < K and !vis[i][x0+1])
q.push({x0+1, (w0+w)/(double)(2), i});
}
}
if(answer == 1e18)
return -1;
else
return answer;
}
// int main(){
// double kk = solve(3, 2, 30, 2, {1, 2}, {2, 0}, {12, 4}, {1, 2, 1});
// double kk1 = solve(4, 4, 30, 3, {0, 0, 1, 2}, {1, 2, 3, 3}, {5, 4, 2, 4}, {1, 0, 2, 1});
// double kk2 = solve(7, 8, 3, 6, {0, 0, 1, 2, 3, 3, 4, 5}, {1, 2, 3, 3, 4, 5, 6, 6}, {2, 4, 6, 8, 10, 12, 14, 16}, {1, 2, 0, 2, 2, 2, 1});
// if(kk == 4.0 and kk1 == 2.0 and kk2 == 20.75)
// puts("Correct.");
// else
// puts("Wrong Answer.");
// return 0;
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2998 ms |
19392 KB |
Correct. |
2 |
Execution timed out |
3064 ms |
19392 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
19964 KB |
Correct. |
2 |
Correct |
68 ms |
20048 KB |
Correct. |
3 |
Correct |
56 ms |
20052 KB |
Correct. |
4 |
Correct |
59 ms |
20048 KB |
Correct. |
5 |
Correct |
58 ms |
20136 KB |
Correct. |
6 |
Correct |
30 ms |
20820 KB |
Correct. |
7 |
Correct |
32 ms |
21080 KB |
Correct. |
8 |
Correct |
25 ms |
21072 KB |
Correct. |
9 |
Correct |
333 ms |
19812 KB |
Correct. |
10 |
Correct |
313 ms |
19796 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
20072 KB |
Correct. |
2 |
Correct |
57 ms |
20052 KB |
Correct. |
3 |
Correct |
57 ms |
20044 KB |
Correct. |
4 |
Correct |
339 ms |
20004 KB |
Correct. |
5 |
Correct |
327 ms |
19796 KB |
Correct. |
6 |
Correct |
14 ms |
20056 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
326 ms |
27032 KB |
Correct. |
2 |
Correct |
394 ms |
20048 KB |
Correct. |
3 |
Correct |
358 ms |
20048 KB |
Correct. |
4 |
Correct |
374 ms |
20056 KB |
Correct. |
5 |
Correct |
482 ms |
19864 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
20104 KB |
Correct. |
2 |
Correct |
61 ms |
20288 KB |
Correct. |
3 |
Correct |
59 ms |
20304 KB |
Correct. |
4 |
Correct |
32 ms |
21776 KB |
Correct. |
5 |
Correct |
324 ms |
19796 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
20304 KB |
Correct. |
2 |
Correct |
56 ms |
20048 KB |
Correct. |
3 |
Correct |
39 ms |
27596 KB |
Correct. |
4 |
Correct |
26 ms |
21084 KB |
Correct. |
5 |
Correct |
336 ms |
19940 KB |
Correct. |
6 |
Correct |
58 ms |
20232 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
618 ms |
20308 KB |
Correct. |
2 |
Correct |
103 ms |
19548 KB |
Correct. |
3 |
Incorrect |
1306 ms |
30664 KB |
Wrong Answer. |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
623 ms |
20360 KB |
Correct. |
2 |
Correct |
102 ms |
19544 KB |
Correct. |
3 |
Correct |
201 ms |
39112 KB |
Correct. |
4 |
Incorrect |
861 ms |
21904 KB |
Wrong Answer. |
5 |
Halted |
0 ms |
0 KB |
- |