#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> g[100005];
bool reach[100005];
void dfsreach(int u, int H) {
if (reach[u])
return;
reach[u] = true;
if (u == H)
return;
for (auto v : g[u]) {
dfsreach(v.first, H);
}
}
long double dist[100005][32];
double solve(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y,
std::vector<int> c, std::vector<int> arr) {
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]});
}
dfsreach(0, H);
if (!reach[H]) {
for (int i = 0; i < N; i++) {
g[i].clear();
reach[i] = false;
}
return -1;
}
priority_queue<pair<long double, int>> pq;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= K; j++)
dist[i][j] = 2e18;
if (arr[i] == 0 && reach[i]) {
pq.push({0, i});
dist[i][0] = 0;
}
}
pq.push({0, 0});
dist[0][0] = 0;
while (!pq.empty()) {
auto cur = pq.top();
pq.pop();
for (auto nxt : g[cur.second]) {
for (int j = 0; j <= K; j++) {
if (arr[nxt.first] == 2) {
if (dist[nxt.first][j + 1] >
(-cur.first + nxt.second) * 0.5L) {
dist[nxt.first][j + 1] =
(-cur.first + nxt.second) * 0.5L;
pq.push({-dist[nxt.first][j + 1], nxt.first});
}
}
if (dist[nxt.first][j] > -cur.first + nxt.second) {
dist[nxt.first][j] = -cur.first + nxt.second;
pq.push({-dist[nxt.first][j], nxt.first});
}
}
}
}
for (int i = 0; i < N; i++) {
g[i].clear();
reach[i] = false;
}
long double mn = 2e18;
for (int j = 0; j <= K; j++) {
mn = min(mn, dist[H][j]);
}
if (mn > 1e18)
return -1;
else
return mn;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
256 ms |
3156 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
469 ms |
3716 KB |
Correct. |
2 |
Correct |
584 ms |
3724 KB |
Correct. |
3 |
Correct |
533 ms |
3800 KB |
Correct. |
4 |
Correct |
555 ms |
3712 KB |
Correct. |
5 |
Correct |
560 ms |
3716 KB |
Correct. |
6 |
Correct |
479 ms |
11308 KB |
Correct. |
7 |
Correct |
633 ms |
11140 KB |
Correct. |
8 |
Correct |
251 ms |
17960 KB |
Correct. |
9 |
Correct |
487 ms |
2924 KB |
Correct. |
10 |
Correct |
493 ms |
2864 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
800 ms |
5180 KB |
Correct. |
2 |
Correct |
738 ms |
5104 KB |
Correct. |
3 |
Correct |
717 ms |
5144 KB |
Correct. |
4 |
Correct |
668 ms |
3160 KB |
Correct. |
5 |
Correct |
670 ms |
3188 KB |
Correct. |
6 |
Correct |
139 ms |
15552 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3067 ms |
52328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
340 ms |
3824 KB |
Correct. |
2 |
Correct |
408 ms |
3796 KB |
Correct. |
3 |
Correct |
434 ms |
3832 KB |
Correct. |
4 |
Correct |
545 ms |
11844 KB |
Correct. |
5 |
Correct |
299 ms |
2972 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
552 ms |
5096 KB |
Correct. |
2 |
Correct |
503 ms |
5044 KB |
Correct. |
3 |
Correct |
43 ms |
7852 KB |
Correct. |
4 |
Correct |
415 ms |
19264 KB |
Correct. |
5 |
Correct |
462 ms |
2976 KB |
Correct. |
6 |
Correct |
538 ms |
5108 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3054 ms |
9456 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3037 ms |
138364 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |