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;
vector<vector<int>> conns;
vector<vector<int>> costs;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
conns.resize(N);
costs.resize(N);
for (int i = 0; i < M; i++){
int a = R[i][0];
int b = R[i][1];
conns[a].push_back(b);
conns[b].push_back(a);
costs[a].push_back(L[i]);
costs[b].push_back(L[i]);
}
const long long big = 1000000000;//100000000000000000LL;
vector<long long> firstCost(N, big);
vector<long long> secondCost(N, big);
priority_queue<pair<long long, int>> pq;
for (int i = 0; i < K; i++){
pq.push({0, P[i]});
}
vector<bool> visited(N, 0);
while (!pq.empty()){
int pos;
long long cost;
do{
pos = pq.top().second;
cost = -pq.top().first;
pq.pop();
}while(visited[pos] && !pq.empty());
if (visited[pos]) break;
visited[pos] = 1;
for (unsigned int i = 0; i < conns[pos].size(); i++){
if (!visited[conns[pos][i]]){
long long c = cost + costs[pos][i];
if (c < secondCost[conns[pos][i]]){
if (c < firstCost[conns[pos][i]]){
secondCost[conns[pos][i]] = firstCost[conns[pos][i]];
firstCost[conns[pos][i]] = c;
}else{
secondCost[conns[pos][i]] = c;
}
pq.push({-secondCost[conns[pos][i]], conns[pos][i]});
}
}
}
}
return secondCost[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... |