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>
#include "crocodile.h"
using namespace std;
using ll = long long;
const ll inf = 1e15;
int travel_plan(int n, int m, int r[][2], int l[], int k, int p[]) {
vector<vector<pair<ll, int>>> dx(n);
vector<vector<ll>> dp(n, vector<ll>(2, inf));
vector<bool> viz(n);
for(int i=0; i<m; i++) {
dx[r[i][0]].emplace_back(l[i], r[i][1]);
dx[r[i][1]].emplace_back(l[i], r[i][0]);
}
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
for(int i=0; i<k; i++) {
pq.emplace(0, p[i]);
dp[p[i]][0] = 0;
dp[p[i]][1] = 0;
}
while(pq.empty() == false) {
pair<ll, int> temp = pq.top(); pq.pop();
ll cost = temp.first;
int u = temp.second;
if(viz[u]) continue;
viz[u] = true;
for(auto i : dx[u]) {
ll nc = cost + i.first;
int v = i.second;
if(dp[v][0] > nc) {
dp[v][1] = dp[v][0];
dp[v][0] = nc;
pq.emplace(dp[v][1], v);
}
else if(dp[v][1] > nc) {
dp[v][1] = nc;
pq.emplace(dp[v][1], v);
}
}
}
return dp[0][1];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |