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>
using namespace std;
typedef long long ll;
int travel_plan(int n, int m, int r[][2], int l[], int k, int p[]) {
vector<vector<pair<ll, ll>>> adj(n);
for (ll i = 0; i < m; ++i) {
adj[r[i][0]].push_back({r[i][1], l[i]});
adj[r[i][1]].push_back({r[i][0], l[i]});
}
priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
vector<priority_queue<ll>> best2(n);
for (ll i = 0; i < k; ++i) {
pq.push({0, p[i]});
best2[p[i]].push(0);
best2[p[i]].push(0);
}
vector<bool> vis(n);
while (!pq.empty()) {
pair<ll, ll> state = pq.top();
pq.pop();
if (state.first > best2[state.second].top()) continue;
if (!state.second) {
return state.first;
}
if (vis[state.second]) throw 1;
vis[state.second] = 1;
for (pair<ll, ll>& edge : adj[state.second]) {
if (best2[edge.first].size() < 2) {
best2[edge.first].push(state.first + edge.second);
if (best2[edge.first].size() == 2) pq.push({best2[edge.first].top(), edge.first});
} else if (state.first + edge.second < best2[edge.first].top()) {
best2[edge.first].pop();
best2[edge.first].push(state.first + edge.second);
pq.push({best2[edge.first].top(), edge.first});
}
}
}
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... |