#include "crocodile.h"
#include <tuple>
#include <utility>
#include <iostream>
#include <queue>
#include <vector>
using i64 = int64_t;
struct Node {
i64 dist;
i64 index;
bool operator<(const Node &rhs) const {
return std::tie(rhs.dist, index) < std::tie(dist, rhs.index);
}
};
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
std::vector<std::vector<std::pair<i64, i64>>> adj(N);
for (i64 i = 0; i < M; i++) {
adj[R[i][0]].push_back({R[i][1], L[i]});
adj[R[i][1]].push_back({R[i][0], L[i]});
}
std::vector<i64> distances(N, 1e18);
std::vector<i64> distances2(N, 1e18);
std::priority_queue<Node> pq;
for (i64 i = 0; i < K; i++) {
distances[P[i]] = 0;
distances2[P[i]] = 0;
pq.push(Node{.dist = 0, .index = P[i]});
}
while (!pq.empty()) {
auto [dist, index] = pq.top();
pq.pop();
if (dist > distances2[index])
continue;
if (index == 0)
return dist;
for (auto [x, d] : adj[index]) {
i64 new_dist = dist + d;
if (new_dist < distances[x]) {
distances2[x] = distances[x];
distances[x] = new_dist;
if (distances2[x] != 1e18) {
pq.push(Node{.dist = distances2[x], .index = x});
}
} else if (new_dist < distances2[x]) {
distances2[x] = new_dist;
pq.push(Node{.dist = new_dist, .index = x});
}
}
}
return N;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
340 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 |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
960 KB |
Output is correct |
13 |
Correct |
4 ms |
1080 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
340 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 |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
960 KB |
Output is correct |
13 |
Correct |
4 ms |
1080 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
372 KB |
Output is correct |
16 |
Correct |
316 ms |
69496 KB |
Output is correct |
17 |
Correct |
59 ms |
17616 KB |
Output is correct |
18 |
Correct |
65 ms |
20020 KB |
Output is correct |
19 |
Correct |
369 ms |
77024 KB |
Output is correct |
20 |
Correct |
230 ms |
56764 KB |
Output is correct |
21 |
Correct |
27 ms |
8060 KB |
Output is correct |
22 |
Incorrect |
254 ms |
52412 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |