#include <bits/stdc++.h>
#include "crocodile.h"
using ll = long long;
using namespace std;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
vector<vector<pair<int, ll>>> adj(N);
for (int i = 0; i < M; ++i) {
adj[R[i][0]].emplace_back(R[i][1], L[i]);
adj[R[i][1]].emplace_back(R[i][0], L[i]);
}
vector<array<ll, 2>> v(N, {LLONG_MAX/4, LLONG_MAX/4});
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<>> pq;
for (int i = 0; i < K; ++i) {
v[P[i]] = {0, 0};
pq.emplace(0, P[i]);
}
vector<bool> bio(N);
while (!pq.empty()) {
auto [c, ver] = pq.top();
pq.pop();
if (bio[ver]) continue;
bio[ver] = true;
for (auto [u, w] : adj[ver]) if (!bio[u]) {
if (c + w < v[u][0]) {
v[u][1] = v[u][0];
v[u][0] = c + w;
} else if (c + w < v[u][1]) {
v[u][1] = c + w;
} else continue;
pq.emplace(v[u][1], u);
}
}
return v[0][1];
}
/*
int main() {
*/
/*int R[][2] = {{0, 2}, {0, 3}, {3, 2}, {2, 1}, {0, 1}, {0, 4}, {3, 4}};
int L[] = {4,3,2,10,100,7,9};
int P[] = {1, 3};
int N = 5;
int M = 7;
int K = 2;*//*
int R[][2] = {{0, 1}, {0, 2}, {3, 2}, {2, 4}};
int L[] = {2, 3, 1, 4};
int P[] = {1, 3, 4};
int N = 5;
int M = 4;
int K = 3;
cout << travel_plan(N, M, R, L, K, P) << '\n';
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
716 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
5 ms |
972 KB |
Output is correct |
13 |
Correct |
4 ms |
1064 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
716 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
5 ms |
972 KB |
Output is correct |
13 |
Correct |
4 ms |
1064 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
578 ms |
81308 KB |
Output is correct |
17 |
Correct |
151 ms |
19736 KB |
Output is correct |
18 |
Correct |
152 ms |
22180 KB |
Output is correct |
19 |
Correct |
762 ms |
90692 KB |
Output is correct |
20 |
Correct |
322 ms |
65756 KB |
Output is correct |
21 |
Correct |
49 ms |
8660 KB |
Output is correct |
22 |
Correct |
358 ms |
62476 KB |
Output is correct |