#include <bits/stdc++.h>
#include "cyberland.h"
#include <vector>
using namespace std;
using ll = long long;
const ll INF = 1e18;
vector<vector<ll> > adjList;
map<pair<ll, ll>, double> weightMat;
double dijkstras(ll startingNode, vector<int> &A) {
ll N = adjList.size();
priority_queue<pair<double, ll>, vector<pair<double, ll> >, greater<pair<double, ll> > > pq;
pq.push({0.0, startingNode});
vector<double> distances(N, (double)INF);
distances[startingNode] = 0.0;
while (!pq.empty()) {
auto [currentDistance, currentNode] = pq.top();
pq.pop();
if (currentDistance > distances[currentNode]) {
continue;
}
for (ll v: adjList[currentNode]) {
if (currentDistance + weightMat[{currentNode, v}] < distances[v]) {
distances[v] = currentDistance + weightMat[{currentNode, v}];
pq.push({distances[v], v});
}
}
}
double minimumPossible = INF;
for (ll i = 0; i < N; i++) {
if (A[i] == 0 || i == 0) minimumPossible = min(minimumPossible, distances[i]);
}
return minimumPossible;
}
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
adjList.clear();
weightMat.clear();
adjList.resize(N);
for (ll i = 0; i < M; i++) {
adjList[x[i]].push_back(y[i]);
adjList[y[i]].push_back(x[i]);
weightMat[{x[i], y[i]}] = (double)c[i];
weightMat[{y[i], x[i]}] = (double)c[i];
}
double response = dijkstras(H, arr);
if (response >= INF) {
return -1.0;
} else {
return response;
}
}
# | 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... |