#include "crocodile.h"
#include<bits/stdc++.h>
using namespace std;
#define INIT ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
int p[100010], k;
vector<pii> g[100010];
bool v[100010];
int d[100010][2];
void tricky_dijkstra(){
multiset<pii> ms;
for(int i=1; i<=k; i++){
ms.insert({0, p[i]});
v[p[i]]=true;
}
while(!ms.empty()){
auto pr=(*ms.begin()); ms.erase(ms.begin());
int node=pr.sc, d0=pr.ft;
v[node]=true;
if(node==0){
break;
}
for(auto pr:g[node]){
int u=pr.ft, c=pr.sc;
if(!v[u]){
auto it=ms.find({d[u][1], u});
if(it==ms.end()){
if(d[u][0]==0){
d[u][0]=d0+c;
}
else{
d[u][1]=d0+c;
if(d[u][1]<d[u][0]){
swap(d[u][1], d[u][0]);
}
ms.insert({d[u][1], u});
}
}
else{
if( (d0+c)<d[u][1] ){
d[u][1]=(d0+c);
if(d[u][1]<d[u][0]){
swap(d[u][1], d[u][0]);
}
ms.erase(it);
ms.insert({d[u][1], u});
}
}
}
}
}
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
k=K;
for(int i=0; i<k; i++){
p[i+1]=P[i];
}
for(int i=0; i<M; i++){
int u=R[i][0], v=R[i][1], c=L[i];
g[u].pb({v, c});
g[v].pb({u, c});
}
tricky_dijkstra();
return d[0][1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2796 KB |
Output is correct |
2 |
Correct |
2 ms |
2668 KB |
Output is correct |
3 |
Correct |
2 ms |
2796 KB |
Output is correct |
4 |
Correct |
3 ms |
2796 KB |
Output is correct |
5 |
Correct |
3 ms |
2796 KB |
Output is correct |
6 |
Correct |
3 ms |
2796 KB |
Output is correct |
7 |
Correct |
3 ms |
2796 KB |
Output is correct |
8 |
Correct |
3 ms |
2796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2796 KB |
Output is correct |
2 |
Correct |
2 ms |
2668 KB |
Output is correct |
3 |
Correct |
2 ms |
2796 KB |
Output is correct |
4 |
Correct |
3 ms |
2796 KB |
Output is correct |
5 |
Correct |
3 ms |
2796 KB |
Output is correct |
6 |
Correct |
3 ms |
2796 KB |
Output is correct |
7 |
Correct |
3 ms |
2796 KB |
Output is correct |
8 |
Correct |
3 ms |
2796 KB |
Output is correct |
9 |
Correct |
4 ms |
2924 KB |
Output is correct |
10 |
Correct |
2 ms |
2668 KB |
Output is correct |
11 |
Correct |
3 ms |
2796 KB |
Output is correct |
12 |
Correct |
6 ms |
3180 KB |
Output is correct |
13 |
Correct |
6 ms |
3180 KB |
Output is correct |
14 |
Correct |
2 ms |
2700 KB |
Output is correct |
15 |
Correct |
3 ms |
2796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2796 KB |
Output is correct |
2 |
Correct |
2 ms |
2668 KB |
Output is correct |
3 |
Correct |
2 ms |
2796 KB |
Output is correct |
4 |
Correct |
3 ms |
2796 KB |
Output is correct |
5 |
Correct |
3 ms |
2796 KB |
Output is correct |
6 |
Correct |
3 ms |
2796 KB |
Output is correct |
7 |
Correct |
3 ms |
2796 KB |
Output is correct |
8 |
Correct |
3 ms |
2796 KB |
Output is correct |
9 |
Correct |
4 ms |
2924 KB |
Output is correct |
10 |
Correct |
2 ms |
2668 KB |
Output is correct |
11 |
Correct |
3 ms |
2796 KB |
Output is correct |
12 |
Correct |
6 ms |
3180 KB |
Output is correct |
13 |
Correct |
6 ms |
3180 KB |
Output is correct |
14 |
Correct |
2 ms |
2700 KB |
Output is correct |
15 |
Correct |
3 ms |
2796 KB |
Output is correct |
16 |
Correct |
873 ms |
56480 KB |
Output is correct |
17 |
Correct |
85 ms |
13932 KB |
Output is correct |
18 |
Correct |
93 ms |
15340 KB |
Output is correct |
19 |
Correct |
994 ms |
59908 KB |
Output is correct |
20 |
Correct |
310 ms |
49660 KB |
Output is correct |
21 |
Correct |
44 ms |
7788 KB |
Output is correct |
22 |
Correct |
392 ms |
46060 KB |
Output is correct |