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 "cyberland.h"
#include <bits/stdc++.h>
#include <vector>
#define pll pair<ll, ll>
#define ll long long
using namespace std;
struct node {
ll v, w;
};
void dijkstra(vector<vector<node> >& graph, vector<ll>& distances, vector<int>& t, ll startIndex) {
priority_queue<pll, vector<pll>, greater<> > Q;
distances[startIndex] = 0;
Q.push({0, startIndex});
for(int i = 0; i < graph.size(); i++) {
if(i == startIndex) continue;
if(t[i] == 0) {
distances[i] = 0;
Q.push({0, startIndex});
}
}
while(!Q.empty()) {
ll node = Q.top().second, dist = Q.top().first;
Q.pop();
if(distances[node] < dist) continue;
for(auto [v, w] : graph[node]) {
if(distances[node] + w < distances[v]) {
distances[v] = distances[node] + w;
Q.push({distances[v], v});
}
}
}
}
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) {
vector<vector<node> > graph(N);
for(int i = 0; i < M; i++) {
graph[x[i]].push_back({y[i], c[i]});
graph[y[i]].push_back({x[i], c[i]});
}
vector<ll> distances(N, LLONG_MAX);
dijkstra(graph, distances, arr, 0);
return distances[H];
}
Compilation message (stderr)
cyberland.cpp: In function 'void dijkstra(std::vector<std::vector<node> >&, std::vector<long long int>&, std::vector<int>&, long long int)':
cyberland.cpp:21:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<node> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for(int i = 0; i < graph.size(); i++) {
| ~~^~~~~~~~~~~~~~
# | 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... |