#include "crocodile.h"
#include "bits/stdc++.h"
using namespace std;
#define f first
#define s second
const int INF = 1000000005;
int travel_plan(int n, int m, int r[][2], int l[], int k, int p[]){
// return -1;
vector<pair<int, int> > adj[n];
for(int i=0; i<m; ++i){
adj[r[i][1]].push_back({r[i][0], l[i]});
adj[r[i][0]].push_back({r[i][1], l[i]});
}
vector<pair<int, int> > d(n, {INF, INF});
vector<bool> vis(n, 0);
priority_queue<pair<int, int> > pq;
for(int i=0; i<k; ++i){
d[p[i]].f = d[p[i]].s = 0;
pq.push({0, p[i]});
}
while(!pq.empty()){
/*for(int i=0; i<n; ++i)
cout << d[i].f << " " << d[i].s << endl;
cout << endl;*/
int a = pq.top().s; pq.pop();
if(vis[a]) continue;
vis[a] = 1;
for(auto P : adj[a]){
int b = P.f, w = P.s;
if(d[a].s + w <= d[b].f){
d[b].s = d[b].f;
d[b].f = d[a].s + w;
pq.push({-d[b].s, b});
} else if(d[a].s + w < d[b].s){
d[b].s = d[a].s + w;
pq.push({-d[b].s, b});
}
}
}
//cout << d[0].s << endl;
if(d[0].s == INF) return -1;
return d[0].s;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
4 ms |
724 KB |
Output is correct |
13 |
Correct |
3 ms |
852 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
4 ms |
724 KB |
Output is correct |
13 |
Correct |
3 ms |
852 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
316 KB |
Output is correct |
16 |
Correct |
382 ms |
56864 KB |
Output is correct |
17 |
Correct |
88 ms |
14792 KB |
Output is correct |
18 |
Correct |
96 ms |
16324 KB |
Output is correct |
19 |
Correct |
485 ms |
63156 KB |
Output is correct |
20 |
Correct |
252 ms |
47000 KB |
Output is correct |
21 |
Correct |
35 ms |
6324 KB |
Output is correct |
22 |
Correct |
280 ms |
44624 KB |
Output is correct |