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>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const ll inf = 1e17;
int travel_plan(int n, int m, int R[][2], int L[], int k, int P[]){
vector<vector<pair<int, ll>>> graph(n);
for(int i = 0; i < m; i++){
graph[R[i][0]].pb({R[i][1], L[i]});
graph[R[i][1]].pb({R[i][0], L[i]});
}
vector<ll> dis0(n, inf), dis(n, inf);
vector<bool> bl(n, 0);
priority_queue<pair<ll, int>> pq;
for(int i = 0; i < k; i++){
dis0[P[i]] = 0, dis[P[i]] = 0;
pq.push({0, P[i]});
}
while(!pq.empty()){
int nd = pq.top().sc; pq.pop();
if(bl[nd]) continue;
bl[nd] = 1;
for(auto [x, w]: graph[nd]) if(dis[nd]+w < dis[x]){
if(dis[nd]+w < dis0[x]) dis[x] = dis0[x], dis0[x] = dis[nd]+w;
else dis[x] = dis[nd]+w;
pq.push({-dis[x], x});
}
}
return dis[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... |