#include <bits/stdc++.h>
#include <crocodile.h>
#define ll int
#define pb push_back
#define mp make_pair
#define s second
#define f first
using namespace std;
#define pii pair<int,int>
const int INF = INT_MAX;
int travel_plan(int n,int m,int r[][2],int l[],int k,int p[]){
vector<pii> adj[n];
for(int i =0;i<m;i++){
int u = r[i][0];
int v = r[i][1];
int d = l[i];
adj[u].push_back(make_pair(v,d));
adj[v].push_back(make_pair(u,d));
}
pii dis[n];
int actual[n];
for(int i =0;i<n;i++) dis[i] = mp(INF,INF),actual[i]=INF;
priority_queue<pii,vector<pii>,greater<pii>> pq;
for(int i =0;i<k;i++){
ll u = p[i];
pq.push(mp(0,u));
dis[u].f = 0;
dis[u].s = 0;
actual[u] = 0;
}
vector<bool> vis(n,false);
while(!pq.empty()){
pii u = pq.top();
pq.pop();
if(vis[u.s]) continue;
vis[u.s]=true;
// cout << u.s << endl;
// cout << "NODES : ";
for(auto v:adj[u.s]){
int Dist = actual[u.s] + v.s;
int V = v.f;
// cout << V << ' ';
if(Dist <= dis[V].f){
dis[V].s = dis[V].f;
dis[V].f = Dist;
actual[V] = dis[V].s;
pq.push(mp(actual[V],V));
}
else if(Dist < dis[V].s){
dis[V].s = Dist;
actual[V] = Dist;
pq.push(mp(Dist,V));
}
}
// cout << endl;
}
return dis[0].s;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
380 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
6 ms |
376 KB |
Output is correct |
5 |
Correct |
6 ms |
504 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
504 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
380 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
6 ms |
376 KB |
Output is correct |
5 |
Correct |
6 ms |
504 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
504 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
7 ms |
504 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
6 ms |
376 KB |
Output is correct |
12 |
Correct |
9 ms |
632 KB |
Output is correct |
13 |
Correct |
8 ms |
760 KB |
Output is correct |
14 |
Correct |
5 ms |
508 KB |
Output is correct |
15 |
Correct |
6 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
380 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
6 ms |
376 KB |
Output is correct |
5 |
Correct |
6 ms |
504 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
504 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
7 ms |
504 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
6 ms |
376 KB |
Output is correct |
12 |
Correct |
9 ms |
632 KB |
Output is correct |
13 |
Correct |
8 ms |
760 KB |
Output is correct |
14 |
Correct |
5 ms |
508 KB |
Output is correct |
15 |
Correct |
6 ms |
376 KB |
Output is correct |
16 |
Correct |
572 ms |
41056 KB |
Output is correct |
17 |
Correct |
118 ms |
12148 KB |
Output is correct |
18 |
Correct |
152 ms |
13428 KB |
Output is correct |
19 |
Correct |
727 ms |
47336 KB |
Output is correct |
20 |
Correct |
357 ms |
34424 KB |
Output is correct |
21 |
Correct |
55 ms |
5112 KB |
Output is correct |
22 |
Correct |
388 ms |
30712 KB |
Output is correct |