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;
const long long INF = (long long) 1e18;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
vector< vector< pair<int, long long> > > g(N);
for (int i = 0; i < M; i++) {
g[R[i][0]].push_back({R[i][1], L[i]});
g[R[i][1]].push_back({R[i][0], L[i]});
}
vector<long long> dist1(N, INF), dist2(N, INF);
for (int i = 0; i < K; i++) dist1[P[i]] = dist2[P[i]] = 0;
priority_queue< pair<long long, int>, vector< pair<long long, int> >, greater< pair<long long, int> > > pq;
for (int i = 0; i < K; i++) pq.push({0, P[i]});
while (!pq.empty()) {
int u = pq.top().second;
long long d = pq.top().first; pq.pop();
if (d > dist2[u]) continue;
for (auto& v : g[u]) {
long long prev = dist2[v.first];
if (d + v.second < dist1[v.first]) {
dist2[v.first] = dist1[v.first];
dist1[v.first] = d + v.second;
} else if (d + v.second < dist2[v.first]) {
dist2[v.first] = d + v.second;
}
if (dist2[v.first] != prev) pq.push({dist2[v.first], v.first});
}
}
return dist2[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... |