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<vector>
#include<queue>
using namespace std;
vector<pair<int,int> > Adj[100005];
int Dist[2][100005];
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
for(int 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]});
}
for(int i=0; i<N; i++)
Dist[0][i]=Dist[1][i]=1000000000;
priority_queue<pair<int,int> > Q;
for(int i=0; i<K; i++)
{
Dist[0][P[i]]=Dist[1][P[i]]=0;
Q.push({0,P[i]});
}
while(!Q.empty())
{
int cost=-Q.top().first;
int nod=Q.top().second;
Q.pop();
if(cost!=Dist[1][nod])
continue;
for(auto other:Adj[nod])
{
int newCost=cost+other.second;
if(newCost<Dist[0][other.first])
{
int aux=Dist[0][other.first];
Dist[0][other.first]=newCost;
if(aux!=1000000000)
{
Dist[1][other.first]=aux;
Q.push({-aux,other.first});
}
}
else if(newCost<Dist[1][other.first])
{
Dist[1][other.first]=newCost;
Q.push({-newCost,other.first});
}
}
}
return Dist[1][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... |