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 <bits/stdc++.h>
int travel_plan(int n, int m, int r[][2], int l[], int k, int p[]) {
std::vector <std::vector <std::pair <int, int>>> g(n);
for (int i = 0; i < m; i++) {
g[r[i][0]].emplace_back(r[i][1], l[i]);
g[r[i][1]].emplace_back(r[i][0], l[i]);
}
std::vector <int> cnt(n, 0);
std::priority_queue <std::pair <long long, int>> pq;
for (int i = 0; i < k; i++) {
cnt[p[i]] = 1;
pq.push({ 0, p[i] });
}
while (pq.size()) {
long long w = -pq.top().first;
int v = pq.top().second;
pq.pop();
if (cnt[v] >= 2) {
continue;
}
cnt[v]++;
if (cnt[v] == 1) {
continue;
}
assert(cnt[v] == 2);
if (!v) {
return w;
}
for (auto q : g[v]) {
pq.push({ -w - q.second, q.first });
}
}
assert(false);
return 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... |