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 endl '\n'
#define ll long long
#define all(x) x.begin(), x.end()
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
int n = N, m = M, k = K;
vector<pair<int, int>> g[n + 2];
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]});
}
int vis[n + 2];
memset(vis, 0, sizeof(vis));
priority_queue<pair<ll, int>> pq;
for (int i = 0; i < k; i++) {
vis[P[i]] = 1;
pq.push({0, P[i]});
}
ll ans = 0;
while (pq.size() > 0) {
auto x = pq.top();
pq.pop();
x.first *= -1;
if (vis[x.second] == 0) {
vis[x.second] = 1;
continue;
}
if (vis[x.second] == 2) continue;
if (x.second == 0) {
ans = x.first;
break;
}
vis[x.second] = 2;
for (auto y : g[x.second]) {
if (vis[y.first] == 2) continue;
pq.push({-(x.first + y.second), y.first});
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |