#include <bits/stdc++.h>
#include "cyberland.h"
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define sz size()
#define ll long long
const int N = 1e5 + 5;
vector <pair <int, ll>> v[N];
ll dis[N];
bool vis[N];
void dfs (int x) {
vis[x] = 1;
for (pair <int, ll> i : v[x]) {
if (vis[i.ff]) continue;
dfs (i.ff);
}
}
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
for (int i = 0; i < M; ++i) {
// cout << i << " --> " << x[i] << " " << y[i];
v[x[i]].pb ({y[i], (ll)c[i]});
v[y[i]].pb ({x[i], (ll)c[i]});
}
for (int i = 0; i < N; ++i) {
dis[i] = 1e18;
}
vis[H] = 1;
dfs (0);
vis[H] = 0;
priority_queue <pair <ll, int>, vector <pair <ll, int>>, greater <pair <ll, int>>> q;
q.push ({0, H});
dis[H] = 0;
while (!q.empty()) {
int x = q.top().ss;
q.pop();
for (pair <int, ll> i : v[x]) {
if (dis[i.ff] > dis[x] + i.ss) {
dis[i.ff] = dis[x] + i.ss;
q.push({dis[i.ff], i.ff});
}
}
}
// for (int i = 0; i < N; ++i) {
// cout << i << " -- > " << dis[i] << " " << vis[i] << "\n";
// }
// exit(0);
double jogap;
if (dis[0] != 1e18) {
jogap = dis[0];
for (int i = 1; i < N; ++i) {
if (!arr[i] and vis[i]) {
jogap = min (jogap, (double)dis[i]);
}
}
}
else {
jogap = -1;
}
for (int i = 0; i < N; ++i) {
v[i].clear();
vis[i] = 0;
}
return jogap;
}
//int main() {
// freopen ("input.txt", "r", stdin);
// int T;
// assert(1 == scanf("%d", &T));
// while (T--) {
// int N,M,K,H;
// assert(4 == scanf("%d %d %d\n%d", &N, &M, &K, &H));
// std::vector<int> x(M);
// std::vector<int> y(M);
// std::vector<int> c(M);
// std::vector<int> arr(N);
// for (int i=0;i<N;i++)
// assert(1 == scanf("%d", &arr[i]));
// for (int i=0;i<M;i++)
// assert(3 == scanf("%d %d %d", &x[i], &y[i], &c[i]));
// printf("%.12lf\n", solve(N, M, K, H, x, y, c, arr));
// }
//}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
3676 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
3676 KB |
Correct. |
2 |
Correct |
21 ms |
3672 KB |
Correct. |
3 |
Correct |
19 ms |
3676 KB |
Correct. |
4 |
Correct |
20 ms |
3672 KB |
Correct. |
5 |
Correct |
20 ms |
3672 KB |
Correct. |
6 |
Correct |
18 ms |
4444 KB |
Correct. |
7 |
Correct |
22 ms |
4520 KB |
Correct. |
8 |
Correct |
11 ms |
5208 KB |
Correct. |
9 |
Correct |
19 ms |
3420 KB |
Correct. |
10 |
Correct |
20 ms |
3568 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
3672 KB |
Correct. |
2 |
Correct |
19 ms |
3676 KB |
Correct. |
3 |
Correct |
18 ms |
3692 KB |
Correct. |
4 |
Correct |
20 ms |
3572 KB |
Correct. |
5 |
Correct |
20 ms |
3828 KB |
Correct. |
6 |
Correct |
5 ms |
4184 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
27 ms |
8284 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
3676 KB |
Correct. |
2 |
Correct |
20 ms |
3884 KB |
Correct. |
3 |
Correct |
18 ms |
3676 KB |
Correct. |
4 |
Correct |
19 ms |
4992 KB |
Correct. |
5 |
Correct |
16 ms |
3420 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
3676 KB |
Correct. |
2 |
Correct |
17 ms |
4700 KB |
Correct. |
3 |
Correct |
33 ms |
12004 KB |
Correct. |
4 |
Correct |
13 ms |
5212 KB |
Correct. |
5 |
Correct |
19 ms |
4444 KB |
Correct. |
6 |
Correct |
18 ms |
4700 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
18 ms |
3676 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
18 ms |
3676 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |