#include<bits/stdc++.h>
#include "crocodile.h"
#define inf 1e9 + 10
using namespace std;
const int N = 100010;
vector <pair <int, int>> g[N];
int dist1[N], dist2[N], pai[N];
int travel_plan(int n, int m, int R[][2], int L[], int k, int P[]){
for(int i = 0;i < m;i++){
int a = R[i][0], b = R[i][1], w = L[i];
g[a].push_back({b, w});
g[b].push_back({a, w});
}
for(int i = 0;i <= n;i++) dist1[i] = dist2[i] = inf;
priority_queue <pair <int, int>> pq;
for(int i = 0;i < k;i++){
dist1[P[i]] = dist2[P[i]] = 0;
pq.push({0, P[i]});
}
while(!pq.empty()){
auto [d, v] = pq.top();
pq.pop();
d *= -1;
if(d != dist2[v]) continue;
for(auto [x, w] : g[v]){
if(dist1[x] > dist2[v] + w){
if(pai[x] != v) {
dist2[x] = dist1[x];
if(dist2[x] != inf) pq.push({-dist2[x], x});
}
dist1[x] = dist2[v] + w;
pai[x] = v;
}
else if(dist2[x] > dist2[v] + w and pai[x] != v){
dist2[x] = dist2[v] + w;
pq.push({-dist2[x], x});
}
}
}
return dist2[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
3 ms |
2656 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
2 ms |
2908 KB |
Output is correct |
5 |
Correct |
3 ms |
2908 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2812 KB |
Output is correct |
8 |
Correct |
2 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
3 ms |
2656 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
2 ms |
2908 KB |
Output is correct |
5 |
Correct |
3 ms |
2908 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2812 KB |
Output is correct |
8 |
Correct |
2 ms |
2652 KB |
Output is correct |
9 |
Correct |
3 ms |
2904 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
2 ms |
2892 KB |
Output is correct |
12 |
Correct |
4 ms |
3164 KB |
Output is correct |
13 |
Correct |
3 ms |
3168 KB |
Output is correct |
14 |
Correct |
2 ms |
2656 KB |
Output is correct |
15 |
Correct |
2 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
3 ms |
2656 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
2 ms |
2908 KB |
Output is correct |
5 |
Correct |
3 ms |
2908 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2812 KB |
Output is correct |
8 |
Correct |
2 ms |
2652 KB |
Output is correct |
9 |
Correct |
3 ms |
2904 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
2 ms |
2892 KB |
Output is correct |
12 |
Correct |
4 ms |
3164 KB |
Output is correct |
13 |
Correct |
3 ms |
3168 KB |
Output is correct |
14 |
Correct |
2 ms |
2656 KB |
Output is correct |
15 |
Correct |
2 ms |
2908 KB |
Output is correct |
16 |
Correct |
310 ms |
57568 KB |
Output is correct |
17 |
Correct |
49 ms |
14172 KB |
Output is correct |
18 |
Correct |
61 ms |
15552 KB |
Output is correct |
19 |
Correct |
296 ms |
61660 KB |
Output is correct |
20 |
Correct |
207 ms |
49652 KB |
Output is correct |
21 |
Correct |
21 ms |
7768 KB |
Output is correct |
22 |
Correct |
255 ms |
46204 KB |
Output is correct |