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 "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
using ll = long long;
using ii = pair<int, int>;
ll fd[100005], sd[100005];
vector<pair<int, ll> > adj[100005];
priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > pq;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
for (int i = 0; i < M; i++) {
adj[R[i][0]].eb(R[i][1], L[i]);
adj[R[i][1]].eb(R[i][0], L[i]);
}
for (int i = 0; i < N; i++) {
fd[i] = sd[i] = (ll)1e16;
}
for (int i = 0; i < K; i++) {
fd[P[i]] = sd[P[i]] = 0;
pq.emplace(0, P[i]);
}
while (!pq.empty()) {
auto [d, v] = pq.top();
pq.pop();
if (sd[v] != d) continue;
for (auto [u, w] : adj[v]) {
ll c = d + w;
if (c < sd[u]) {
sd[u] = c;
if (sd[u] < fd[u]) swap(fd[u], sd[u]);
if (sd[u] != (ll)1e16) pq.emplace(sd[u], u);
}
}
}
assert(sd[0] <= (ll)1e9);
return (int)sd[0];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |