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>
int time1[100010],time2[100010],n,m;
std::vector<std::vector<std::pair<int,int>>>a;
std::priority_queue<std::pair<int,int>>q;
bool viz[100010];
void lee()
{
while(!q.empty())
{
int val=-q.top().first;
int nod=q.top().second;
q.pop();
if(viz[nod]==true)
continue;
viz[nod]=true;
for(auto x:a[nod])
{
if(time1[x.first]==0||time1[x.first]>val+x.second)
{
time2[x.first]=time1[x.first];
time1[x.first]=val+x.second;
if(time2[x.first]!=0)
q.push({-time2[x.first],x.first});
}
else if(time2[x.first]==0||time2[x.first]>val+x.second)
{
time2[x.first]=val+x.second;
q.push({-time2[x.first],x.first});
}
}
}
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
n=N;
m=M;
a.resize(n+5);
for(int i=0;i<m;++i)
{
a[R[i][0]].push_back({R[i][1],L[i]});
a[R[i][1]].push_back({R[i][0],L[i]});
}
for(int i=0;i<K;++i)
{
time1[P[i]]=time2[P[i]]=1;
q.push({-1,P[i]});
}
lee();
return time2[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... |