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>
#define F first
#define S second
using namespace std;
typedef int ll;
//ll N1,M1,K1,R1[1000000][2],L1[1000000],P1[100000],solution;
ll x,y,id;
set<pair<ll,ll> >s;
pair<ll,ll>d[100000],p;
bool b[1000000];
vector<vector<pair<ll,ll> > >v;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
v.resize(N);
for(ll i=0; i<M; i++)
{
x=R[i][0],y=R[i][1];
v[x].push_back({y,L[i]});
v[y].push_back({x,L[i]});
}
for(ll i=0; i<N; i++)
d[i]= {2e9,2e9};
for(ll i=0; i<K; i++)
{
d[P[i]]= {0,0};
s.insert({0,P[i]});
}
while(s.size())
{
p=*s.begin();
s.erase(s.begin());
x=p.second,y=p.first;
for(auto z:v[x])
{
id=z.F;
if(d[id].F > y + z.S)
{
s.erase({d[id].S,id});
d[id].S = d[id].F;
d[id].F = y + z.S;
s.insert({d[id].S,id});
}
else if(d[id].S > y+z.S)
{
s.erase({d[id].S,id});
d[id].S = y + z.S;
s.insert({d[id].S,id});
}
}
}
return d[0].S;
}
/*int main()
{
cin>>N1>>M1>>K1;
for(ll i=0; i<M1; i++)
cin>>R1[i][0]>>R1[i][1]>>L1[i];
for(ll i=0; i<K1; i++)
cin>>P1[i];
cin>>solution;
cout<<travel_plan(N1,M1,R1,L1,K1,P1);
}*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |