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 <iostream>
#include <vector>
#include <queue>
#include "crocodile.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<pair<ll,ll>> d(N,{1e18,1e18});
vector<bool> seen(N,false);
vector<vector<pair<int,int>>> g(N,vector<pair<int,int>>());
for(int i=0;i<M;i++){
g[R[i][0]].push_back({R[i][1],L[i]});
g[R[i][1]].push_back({R[i][0],L[i]});
}
priority_queue<pair<ll,int>> pq;
for(int i=0;i<K;i++){
pq.push({0,P[i]});
//seen[P[i]]=true;
d[P[i]].first=d[P[i]].second=0;
}
while(!pq.empty()){
ll dist=-pq.top().first,u=pq.top().second;
pq.pop();
//cout<<u<<' ';
if(dist!=d[u].second)continue;
seen[u]=true;
for(auto v:g[u]){
if(seen[v.first])continue;
if(dist+v.second<d[v.first].first){
d[v.first].second=d[v.first].first;
d[v.first].first=dist+v.second;
pq.push({-d[v.first].second,v.first});
}
else if(dist+v.second<d[v.first].second){
d[v.first].second=dist+v.second;
pq.push({-d[v.first].second,v.first});
}
}
}
return d[0].second;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |