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 int inf = 2e9;
int travel_plan(int n, int m, int R[][2], int L[], int k, int p[]) {
vector<vector<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]);
}
vector<int> height(n, -1);
vector<pair<int, int>> out(n, make_pair(inf, inf));
priority_queue<pair<int, int>> pq;
vector<bool> vis(n);
for (int i = 0; i < k; i++) {
height[p[i]] = 0;
pq.emplace(0, p[i]);
}
while (!pq.empty()) {
auto [d, u] = pq.top(); pq.pop();
if (vis[u]) continue;
d *= -1;
// cout << u << ' ' << d << endl;
vis[u] = true;
height[u] = d;
for (auto [v, w]: g[u]) {
if (vis[v]) continue;
// cout << '\t' << u << ' ' << v << ' ' << w << endl;
if (out[v].first > d + w) {
out[v].second = out[v].first;
out[v].first = d + w;
} else {
out[v].second = min(out[v].second, d + w);
}
if (out[v].second != inf) {
pq.emplace(-out[v].second, v);
}
}
}
return height[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... |