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>
#define range(it, a, b) for (ll it = a; it < b; it++)
#define all(x) begin(x), end(x)
#define ll long long
#define ull unsigned long long
#define INF64 ((ll) 1 << 62)
#define INF32 (1 << 30)
#define mset multiset
#define uset unordered_set
#define umap unordered_map
#define pqueue priority_queue
#define ptr(A) shared_ptr<A>
using namespace std;
struct TPos {
ll i, w;
};
bool operator < (const TPos& a, const TPos& b) {
return a.w > b.w;
}
vector<vector<TPos>> adj;
vector<int> a;
vector<ll> memo;
bool dijkstra(int H) {
pqueue<TPos> pq;
pq.push({0, 0});
TPos t, nt;
while (!pq.empty()) {
t = pq.top();
pq.pop();
if (memo[t.i] < t.w)
continue;
memo[t.i] = t.w;
for (TPos& it : adj[t.i]) {
nt = {it.i, (a[it.i] == 0 ? 0 : memo[t.i] + it.w)};
if (memo[it.i] > nt.w)
pq.push(nt);
}
}
}
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
adj.resize(N);
memo.resize(N, INF64);
a = arr;
range(i, 0, M) {
adj[x[i]].push_back({y[i], c[i]});
adj[y[i]].push_back({x[i], c[i]});
}
dijkstra(H);
return (memo[H] == INF64 ? -1 : memo[H]);
}
Compilation message (stderr)
cyberland.cpp: In function 'bool dijkstra(int)':
cyberland.cpp:48:1: warning: no return statement in function returning non-void [-Wreturn-type]
48 | }
| ^
# | 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... |