#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define ll long long
const int MAX=1e6+10, MAXV=1e9+100;
int n, m, k, ileSpe[MAX], odw[MAX];
int odl[MAX];
bool spe[MAX];
vector<pair<int,int>>g[MAX];
priority_queue<pair<int,int>>kol;
pair<int,int>akt[MAX];
int obl(int x){
return(akt[x].se);
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
n=N, k=K, m=M;
for(int i=1; i<=m; i++)
g[R[i-1][0]+1].pb({R[i-1][1]+1, L[i-1]}), g[R[i-1][1]+1].pb({R[i-1][0]+1, L[i-1]});
for(int i=1; i<=k; i++){
int v=P[i-1]+1;
spe[v]=true;
}
for(int i=1; i<=n; i++){
odl[i]=MAXV;
akt[i]={MAXV, MAXV};
if(spe[i])
kol.push({0, i}), odl[i]=0;
}
while(kol.size()){
auto v=kol.top().se;
kol.pop();
if(odw[v]) continue;
odw[v]=spe[v]=true;
for(auto s: g[v]){
ileSpe[s.fi]++;
if(odl[v]+s.se<=akt[s.fi].fi)
akt[s.fi].se=akt[s.fi].fi, akt[s.fi].fi=odl[v]+s.se;
else if(odl[v]+s.se<akt[s.fi].se)
akt[s.fi].se=odl[v]+s.se;
if(ileSpe[s.fi]>=2){
int nowy=obl(s.fi);
if(odl[s.fi]>nowy)
odl[s.fi]=nowy, kol.push({-nowy, s.fi});
}
}
}
return odl[1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23836 KB |
Output is correct |
3 |
Correct |
16 ms |
23796 KB |
Output is correct |
4 |
Correct |
13 ms |
23908 KB |
Output is correct |
5 |
Correct |
12 ms |
23812 KB |
Output is correct |
6 |
Correct |
12 ms |
23892 KB |
Output is correct |
7 |
Correct |
12 ms |
23892 KB |
Output is correct |
8 |
Correct |
13 ms |
23872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23836 KB |
Output is correct |
3 |
Correct |
16 ms |
23796 KB |
Output is correct |
4 |
Correct |
13 ms |
23908 KB |
Output is correct |
5 |
Correct |
12 ms |
23812 KB |
Output is correct |
6 |
Correct |
12 ms |
23892 KB |
Output is correct |
7 |
Correct |
12 ms |
23892 KB |
Output is correct |
8 |
Correct |
13 ms |
23872 KB |
Output is correct |
9 |
Correct |
13 ms |
24020 KB |
Output is correct |
10 |
Correct |
12 ms |
23856 KB |
Output is correct |
11 |
Correct |
13 ms |
23892 KB |
Output is correct |
12 |
Correct |
15 ms |
24148 KB |
Output is correct |
13 |
Correct |
14 ms |
24272 KB |
Output is correct |
14 |
Correct |
12 ms |
23764 KB |
Output is correct |
15 |
Correct |
14 ms |
23868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23836 KB |
Output is correct |
3 |
Correct |
16 ms |
23796 KB |
Output is correct |
4 |
Correct |
13 ms |
23908 KB |
Output is correct |
5 |
Correct |
12 ms |
23812 KB |
Output is correct |
6 |
Correct |
12 ms |
23892 KB |
Output is correct |
7 |
Correct |
12 ms |
23892 KB |
Output is correct |
8 |
Correct |
13 ms |
23872 KB |
Output is correct |
9 |
Correct |
13 ms |
24020 KB |
Output is correct |
10 |
Correct |
12 ms |
23856 KB |
Output is correct |
11 |
Correct |
13 ms |
23892 KB |
Output is correct |
12 |
Correct |
15 ms |
24148 KB |
Output is correct |
13 |
Correct |
14 ms |
24272 KB |
Output is correct |
14 |
Correct |
12 ms |
23764 KB |
Output is correct |
15 |
Correct |
14 ms |
23868 KB |
Output is correct |
16 |
Correct |
402 ms |
62792 KB |
Output is correct |
17 |
Correct |
89 ms |
33084 KB |
Output is correct |
18 |
Correct |
99 ms |
34476 KB |
Output is correct |
19 |
Correct |
525 ms |
67444 KB |
Output is correct |
20 |
Correct |
296 ms |
58064 KB |
Output is correct |
21 |
Correct |
45 ms |
27980 KB |
Output is correct |
22 |
Correct |
303 ms |
53564 KB |
Output is correct |