#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
#define x first
#define y second
#define pb push_back
vector <pair <long long,long long> > g[N];
for (int i=0; i<M; i++){
g[R[i][0]].pb({R[i][1],L[i]});
g[R[i][1]].pb({R[i][0],L[i]});
}
bool visited[N];
for (int i=0; i<N; i++) visited[i]=0;
pair <long long,long long> mn[N],smn[N];
for (int i=0; i<N; i++){
mn[i]={1e18,1e18};
smn[i]={1e18,1e18};
}
priority_queue <pair <long long,long long>,vector <pair <long long,long long> >,greater <pair <long long,long long> > > pq;
for (int i=0; i<K; i++){
mn[P[i]]={0,-1}; smn[P[i]]={0,-2};
pq.push({0,P[i]});
}
while (!pq.empty()){
pair <long long,long long> tp=pq.top(); pq.pop();
if (visited[tp.y]) continue;
visited[tp.y]=1;
for (pair <long long,long long> i:g[tp.y]){
if (visited[i.x]) continue;
if (mn[i.x].y==tp.y||smn[i.x].y==tp.y) continue;
long long ndist=tp.x+i.y;
if (ndist<=mn[i.x].x){
smn[i.x]=mn[i.x];
mn[i.x]={ndist,tp.y};
pq.push({smn[i.x].x,i.x});
} else if (ndist<smn[i.x].x){
smn[i.x]={ndist,tp.y};
pq.push({smn[i.x].x,i.x});
}
}
}
return smn[0].x;
#undef x
#undef y
#undef pb
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
444 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
444 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
704 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
448 KB |
Output is correct |
12 |
Correct |
4 ms |
1080 KB |
Output is correct |
13 |
Correct |
4 ms |
1108 KB |
Output is correct |
14 |
Correct |
1 ms |
316 KB |
Output is correct |
15 |
Correct |
1 ms |
448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
444 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
704 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
448 KB |
Output is correct |
12 |
Correct |
4 ms |
1080 KB |
Output is correct |
13 |
Correct |
4 ms |
1108 KB |
Output is correct |
14 |
Correct |
1 ms |
316 KB |
Output is correct |
15 |
Correct |
1 ms |
448 KB |
Output is correct |
16 |
Correct |
422 ms |
84104 KB |
Output is correct |
17 |
Correct |
91 ms |
21440 KB |
Output is correct |
18 |
Correct |
110 ms |
23852 KB |
Output is correct |
19 |
Correct |
542 ms |
94992 KB |
Output is correct |
20 |
Correct |
275 ms |
65724 KB |
Output is correct |
21 |
Correct |
53 ms |
9176 KB |
Output is correct |
22 |
Correct |
287 ms |
63564 KB |
Output is correct |