#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 long dist[100005];
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 long, int>> pq;
for (int i = 0; i < N; i++) {
dist[i] = 2e18;
if (arr[i] == 0 && reach[i]) {
pq.push({0, i});
dist[i] = 0;
}
}
pq.push({0, 0});
dist[0] = 0;
while (!pq.empty()) {
auto cur = pq.top();
pq.pop();
for (auto nxt : g[cur.second]) {
if (dist[nxt.first] > -cur.first + nxt.second) {
dist[nxt.first] = -cur.first + nxt.second;
pq.push({-dist[nxt.first], nxt.first});
}
}
}
for (int i = 0; i < N; i++) {
g[i].clear();
reach[i] = false;
}
if (dist[H] > 1e18)
return -1;
else
return dist[H];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
2772 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
2772 KB |
Correct. |
2 |
Correct |
21 ms |
2788 KB |
Correct. |
3 |
Correct |
19 ms |
2760 KB |
Correct. |
4 |
Correct |
20 ms |
2808 KB |
Correct. |
5 |
Correct |
20 ms |
2780 KB |
Correct. |
6 |
Correct |
18 ms |
3456 KB |
Correct. |
7 |
Correct |
22 ms |
3412 KB |
Correct. |
8 |
Correct |
12 ms |
4280 KB |
Correct. |
9 |
Correct |
19 ms |
2720 KB |
Correct. |
10 |
Correct |
19 ms |
2728 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
2812 KB |
Correct. |
2 |
Correct |
21 ms |
2824 KB |
Correct. |
3 |
Correct |
20 ms |
2852 KB |
Correct. |
4 |
Correct |
24 ms |
2644 KB |
Correct. |
5 |
Correct |
21 ms |
2716 KB |
Correct. |
6 |
Correct |
9 ms |
3412 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
24 ms |
7292 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
3028 KB |
Correct. |
2 |
Correct |
22 ms |
2848 KB |
Correct. |
3 |
Correct |
18 ms |
2828 KB |
Correct. |
4 |
Correct |
19 ms |
3540 KB |
Correct. |
5 |
Correct |
16 ms |
2644 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
2868 KB |
Correct. |
2 |
Correct |
17 ms |
2784 KB |
Correct. |
3 |
Correct |
51 ms |
7852 KB |
Correct. |
4 |
Correct |
17 ms |
3540 KB |
Correct. |
5 |
Correct |
20 ms |
2724 KB |
Correct. |
6 |
Correct |
19 ms |
2864 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
2828 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
2772 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |