#include "cyberland.h"
#include<bits/stdc++.h>
using namespace std;
#define vec vector
#define int long long
#define float long double
const float INF = 1e18;
double solve(int32_t N, int32_t M, int32_t K, int32_t H, std::vector<int32_t> x, std::vector<int32_t> y, std::vector<int32_t> c, std::vector<int32_t> t) {
float ans = INF;
int n = N;
int m = M;
int k = K;
priority_queue<pair<pair<int, float>, int>, vector<pair<pair<int, float>, int>>, greater<pair<pair<int, float>, int>>> pq;
vec<vec<bool>> vis(k+2, vec<bool>(n, false));
vec<vec<pair<int, int>>> g(n);
for(int i = 0; i<m; i++) {
g[x[i]].push_back({y[i], c[i]});
g[y[i]].push_back({x[i], c[i]});
}
pq.push({{0, 0}, 0});
vec<bool> dfs_vis(n, false);
vec<int> stk{0};
dfs_vis[0] = true;
while(stk.size() > 0) {
int u = stk.back();
stk.pop_back();
if(u==H) continue;
if(t[u] == 0) {
pq.push({{0, 0}, u});
}
for(auto e : g[u]) {
if(dfs_vis[e.first]) continue;
stk.push_back(e.first);
dfs_vis[e.first] = true;
}
}
while(pq.size() > 0) {
pair<pair<int, float>, int> cur = pq.top();
pq.pop();
int ck = cur.first.first;
float d = cur.first.second;
int u = cur.second;
if(ck > k) break;
if(u == H) {
ans = min(ans, d);
continue;
}
if(vis[ck][u]) {
continue;
}
vis[ck][u] = true;
for(auto e : g[u]) {
int v = e.first;
float w = e.second;
if(vis[ck][v]) continue;
pq.push({{ck, d+w}, v});
if(t[v] == 2) {
pq.push({{ck+1, (d+w)/2}, v});
}
}
}
if(abs(ans - INF) < 1000) return -1;
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
592 KB |
Correct. |
2 |
Correct |
27 ms |
728 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
600 KB |
Correct. |
2 |
Correct |
23 ms |
600 KB |
Correct. |
3 |
Correct |
26 ms |
604 KB |
Correct. |
4 |
Correct |
30 ms |
604 KB |
Correct. |
5 |
Correct |
23 ms |
604 KB |
Correct. |
6 |
Correct |
19 ms |
1692 KB |
Correct. |
7 |
Correct |
25 ms |
1696 KB |
Correct. |
8 |
Correct |
19 ms |
2780 KB |
Correct. |
9 |
Correct |
25 ms |
512 KB |
Correct. |
10 |
Correct |
40 ms |
496 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
604 KB |
Correct. |
2 |
Correct |
39 ms |
604 KB |
Correct. |
3 |
Correct |
25 ms |
604 KB |
Correct. |
4 |
Correct |
33 ms |
348 KB |
Correct. |
5 |
Correct |
32 ms |
520 KB |
Correct. |
6 |
Correct |
7 ms |
1824 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
164 ms |
7508 KB |
Correct. |
2 |
Incorrect |
185 ms |
1328 KB |
Wrong Answer. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
688 KB |
Correct. |
2 |
Correct |
25 ms |
604 KB |
Correct. |
3 |
Correct |
26 ms |
692 KB |
Correct. |
4 |
Correct |
25 ms |
1832 KB |
Correct. |
5 |
Correct |
24 ms |
500 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
652 KB |
Correct. |
2 |
Correct |
22 ms |
604 KB |
Correct. |
3 |
Correct |
36 ms |
8832 KB |
Correct. |
4 |
Correct |
18 ms |
1916 KB |
Correct. |
5 |
Correct |
29 ms |
348 KB |
Correct. |
6 |
Correct |
28 ms |
600 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
318 ms |
616 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3069 ms |
102488 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |