#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const ll inf = 1e17;
int travel_plan(int n, int m, int R[][2], int L[], int k, int P[]){
vector<vector<pair<int, ll>>> graph(n);
for(int i = 0; i < m; i++){
graph[R[i][0]].pb({R[i][1], L[i]});
graph[R[i][1]].pb({R[i][0], L[i]});
}
vector<ll> dis0(n, inf), dis(n, inf);
vector<bool> bl(n, 0);
priority_queue<pair<ll, int>> pq;
for(int i = 0; i < k; i++){
dis0[P[i]] = 0, dis[P[i]] = 0;
pq.push({0, P[i]});
}
while(!pq.empty()){
int nd = pq.top().sc; pq.pop();
if(bl[nd]) continue;
bl[nd] = 1;
for(auto [x, w]: graph[nd]) if(dis[nd]+w < dis[x]){
if(dis[nd]+w < dis0[x]) dis[x] = dis0[x], dis0[x] = dis[nd]+w;
else dis[x] = dis[nd]+w;
pq.push({-dis[x], x});
}
}
return dis[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
452 KB |
Output is correct |
5 |
Correct |
1 ms |
444 KB |
Output is correct |
6 |
Correct |
1 ms |
312 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 |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
452 KB |
Output is correct |
5 |
Correct |
1 ms |
444 KB |
Output is correct |
6 |
Correct |
1 ms |
312 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 |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
980 KB |
Output is correct |
13 |
Correct |
4 ms |
1084 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
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 |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
452 KB |
Output is correct |
5 |
Correct |
1 ms |
444 KB |
Output is correct |
6 |
Correct |
1 ms |
312 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 |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
980 KB |
Output is correct |
13 |
Correct |
4 ms |
1084 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
446 ms |
83560 KB |
Output is correct |
17 |
Correct |
88 ms |
19776 KB |
Output is correct |
18 |
Correct |
117 ms |
22228 KB |
Output is correct |
19 |
Correct |
556 ms |
93460 KB |
Output is correct |
20 |
Correct |
312 ms |
65744 KB |
Output is correct |
21 |
Correct |
39 ms |
8676 KB |
Output is correct |
22 |
Correct |
299 ms |
63024 KB |
Output is correct |