This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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
#define pii pair <int, ll>
#define piii pair <ll, int>
const int N = 1e5 + 5;
vector <pii> v[N];
priority_queue <piii, vector <piii>, greater <piii>> q;
ll dis[N];
bool vis[N];
void dfs (int x) {
vis[x] = 1;
for (pii 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;
q.push ({0, H});
dis[H] = 0;
while (!q.empty()) {
int x = q.top().ss;
q.pop();
for (pii 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);
arr[0] = 0;
double jogap = -1;
for (int i = 0; i < N; ++i) {
if (!arr[i] and vis[i]) {
if (jogap == -1) {
jogap = (double)dis[i];
}
else jogap = min (jogap, (double)dis[i]);
}
}
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));
// }
//}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |