#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);
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
448 KB |
Output is correct |
9 |
Correct |
3 ms |
588 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
3 ms |
332 KB |
Output is correct |
12 |
Correct |
5 ms |
716 KB |
Output is correct |
13 |
Correct |
4 ms |
844 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
448 KB |
Output is correct |
9 |
Correct |
3 ms |
588 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
3 ms |
332 KB |
Output is correct |
12 |
Correct |
5 ms |
716 KB |
Output is correct |
13 |
Correct |
4 ms |
844 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
641 ms |
54772 KB |
Output is correct |
17 |
Correct |
91 ms |
13636 KB |
Output is correct |
18 |
Correct |
150 ms |
15236 KB |
Output is correct |
19 |
Correct |
886 ms |
60132 KB |
Output is correct |
20 |
Correct |
306 ms |
47172 KB |
Output is correct |
21 |
Correct |
48 ms |
6024 KB |
Output is correct |
22 |
Correct |
369 ms |
44228 KB |
Output is correct |