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;
typedef long long i64;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
vector<vector<pair<int, i64>>> edges(N);
for (int i = 0; i < M; ++i) {
edges[R[i][1]].emplace_back(R[i][0], i64(L[i]));
edges[R[i][0]].emplace_back(R[i][1], i64(L[i]));
}
vector<int> visited(N, 0);
vector<i64> d(N, 1e18);
priority_queue<pair<i64, int>> q;
for (int i = 0; i < K; ++i) {
visited[P[i]] = 1;
d[P[i]] = 0;
q.push({0, P[i]});
}
while (!q.empty()) {
i64 dist = -q.top().first;
int node = q.top().second;
q.pop();
if (visited[node] >= 2) continue;
++visited[node];
if (visited[node] < 2) continue;
d[node] = dist;
for (auto [next, weight] : edges[node]) {
if (visited[next] < 2) {
q.push({-dist - weight, next});
}
}
}
return d[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... |