#include <bits/stdc++.h>
#define Longgggg ios_base::sync_with_stdio(0); cin.tie(0);
#define ll long long
#define endl '\n'
using namespace std;
// Bitwise
#define MASK(i) (1LL << (i))
#define BIT(x, i) (1LL & ((x) >> (i)))
#define ON(x, i) ((x) | MASK(i))
#define OFF(x, i) ((x) & ~MASK(i))
#define LASTBIT(mask) ((mask) & -(mask))
// Other
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define mod(x, k) ((((x) % (k)) + (k)) % (k))
#define all(x) begin(x), end(x)
#define fi first
#define se second
#define IN "A.in"
#define OUT "A.out"
#define DEBUG "debug.out"
const int INF = (int) 1e9+5;
const ll LINF = (ll) 1e18;
const ll MOD = (ll) 1e9+7;
const int mxN = 100005;
ll travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
int n = N, m = M, k = K;
vector <vector <pair <ll, ll>>> adj(n);
FOR(i, 0, m-1) {
adj[R[i][0]].push_back({R[i][1], L[i]});
adj[R[i][1]].push_back({R[i][0], L[i]});
}
// Dijkstra from exits
priority_queue <pair <ll, ll>, vector <pair <ll, ll>>, greater<>> q;
vector <ll> d(n, LINF); // Two shortest distance
vector <int> vis(n, 0);
FOR(i, 0, k-1) {
q.push({0, P[i]});
d[P[i]] = 0;
vis[P[i]] = 1;
}
while (!q.empty()) {
ll u = q.top().se, dis = q.top().fi;
q.pop();
if (!vis[u]) {
vis[u] = 1;
continue;
}
if (u == 0) return dis;
if (vis[u] > 1) continue;
++vis[u];
for (auto &x : adj[u]) {
ll v = x.fi, w = x.se;
if (vis[v] > 1) continue;
q.push({dis + w, v});
}
}
}
Compilation message (stderr)
crocodile.cpp: In function 'long long int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:70:1: warning: control reaches end of non-void function [-Wreturn-type]
70 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |