#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
//cout << "??" << endl;
vector<pair<int, int>> tree[N];
for(int i = 0; i < M; i ++){
tree[R[i][0]].push_back({R[i][1], L[i]});
tree[R[i][1]].push_back({R[i][0], L[i]});
}
// cout << "???" << endl;
priority_queue<pair<int, int>> que;
vector<int> dist(N, 1e9), cc(N);
for(int i = 0; i < K; i++){
cc[P[i]] = 2;
for(auto [l ,r] : tree[P[i]])
que.push({-r, l});
}
while(!que.empty()){
int a = -que.top().first, b = que.top().second;
//cout << b << " " << a << endl;
que.pop();
if(cc[b] != 1){
cc[b]++;
continue;
}
cc[b]++;
dist[b] = a;
for(auto [l, r] : tree[b]){
que.push({-r-a, l});
}
}
return dist[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 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 |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 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 |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
5 ms |
980 KB |
Output is correct |
13 |
Correct |
4 ms |
1108 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 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 |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
5 ms |
980 KB |
Output is correct |
13 |
Correct |
4 ms |
1108 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
657 ms |
71268 KB |
Output is correct |
17 |
Correct |
62 ms |
13716 KB |
Output is correct |
18 |
Correct |
91 ms |
15264 KB |
Output is correct |
19 |
Correct |
645 ms |
75512 KB |
Output is correct |
20 |
Correct |
453 ms |
63768 KB |
Output is correct |
21 |
Correct |
32 ms |
5972 KB |
Output is correct |
22 |
Correct |
419 ms |
44880 KB |
Output is correct |