#include "crocodile.h"
#include <vector>
#define INF 1000000000
#define MAXN 100000
struct myc {
int best, next;
inline bool operator < (const myc &u) const {
return next < u.next;
}
} d[MAXN];
struct mom {
int x, y;
};
std::vector < mom > g[MAXN];
int heap[MAXN + 1], poz[MAXN];
bool done[MAXN];
inline void mySwap(int p, int q) {
int aux = heap[p];
heap[p] = heap[q];
heap[q] = aux;
poz[heap[p]] = p;
poz[heap[q]] = q;
}
inline void urcare(int p) {
while (p > 1 && d[heap[p]] < d[heap[p / 2]]) {
mySwap(p, p / 2);
p /= 2;
}
}
inline void coborare(int p) {
int q;
bool f = 1;
while (f && (q = 2 * p) <= heap[0]) {
if (q < heap[0] && d[heap[q + 1]] < d[heap[q]])
q++;
if (d[heap[q]] < d[heap[p]]) {
mySwap(p, q);
p = q;
} else
f = 0;
}
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
for (int i = 0; i < M; i++) g[R[i][0]].push_back({R[i][1], L[i]}), g[R[i][1]].push_back({R[i][0], L[i]});
for (int i = 0; i < N; i++) d[i] = {INF, INF}, done[i] = 0;
for (int i = 0; i < K; i++) d[P[i]] = {0, 0};
for (int i = 0; i < N; i++) heap[i + 1] = i, poz[i] = i + 1;
heap[0] = N;
for (int i = N; i > 0; i--)
coborare(i);
while (heap[1] != 0) {
int x = heap[1];
done[x] = 1;
for (auto &y : g[x]) {
if (done[y.x] == 0) {
long long val = d[x].next + y.y;
if (val < d[y.x].next) {
if (val < d[y.x].best) {
d[y.x].next = d[y.x].best;
d[y.x].best = val;
} else
d[y.x].next = val;
urcare(poz[y.x]);
}
}
}
d[x] = {INF, INF};
coborare(1);
}
return d[0].next;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2688 KB |
Output is correct |
2 |
Correct |
4 ms |
2688 KB |
Output is correct |
3 |
Correct |
4 ms |
2688 KB |
Output is correct |
4 |
Correct |
5 ms |
2688 KB |
Output is correct |
5 |
Correct |
5 ms |
2816 KB |
Output is correct |
6 |
Correct |
4 ms |
2816 KB |
Output is correct |
7 |
Correct |
5 ms |
2816 KB |
Output is correct |
8 |
Correct |
5 ms |
2816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2688 KB |
Output is correct |
2 |
Correct |
4 ms |
2688 KB |
Output is correct |
3 |
Correct |
4 ms |
2688 KB |
Output is correct |
4 |
Correct |
5 ms |
2688 KB |
Output is correct |
5 |
Correct |
5 ms |
2816 KB |
Output is correct |
6 |
Correct |
4 ms |
2816 KB |
Output is correct |
7 |
Correct |
5 ms |
2816 KB |
Output is correct |
8 |
Correct |
5 ms |
2816 KB |
Output is correct |
9 |
Correct |
6 ms |
3072 KB |
Output is correct |
10 |
Correct |
4 ms |
2688 KB |
Output is correct |
11 |
Correct |
5 ms |
2816 KB |
Output is correct |
12 |
Correct |
8 ms |
3200 KB |
Output is correct |
13 |
Correct |
7 ms |
3200 KB |
Output is correct |
14 |
Correct |
4 ms |
2688 KB |
Output is correct |
15 |
Correct |
5 ms |
2816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2688 KB |
Output is correct |
2 |
Correct |
4 ms |
2688 KB |
Output is correct |
3 |
Correct |
4 ms |
2688 KB |
Output is correct |
4 |
Correct |
5 ms |
2688 KB |
Output is correct |
5 |
Correct |
5 ms |
2816 KB |
Output is correct |
6 |
Correct |
4 ms |
2816 KB |
Output is correct |
7 |
Correct |
5 ms |
2816 KB |
Output is correct |
8 |
Correct |
5 ms |
2816 KB |
Output is correct |
9 |
Correct |
6 ms |
3072 KB |
Output is correct |
10 |
Correct |
4 ms |
2688 KB |
Output is correct |
11 |
Correct |
5 ms |
2816 KB |
Output is correct |
12 |
Correct |
8 ms |
3200 KB |
Output is correct |
13 |
Correct |
7 ms |
3200 KB |
Output is correct |
14 |
Correct |
4 ms |
2688 KB |
Output is correct |
15 |
Correct |
5 ms |
2816 KB |
Output is correct |
16 |
Correct |
649 ms |
56340 KB |
Output is correct |
17 |
Correct |
174 ms |
14600 KB |
Output is correct |
18 |
Correct |
103 ms |
16120 KB |
Output is correct |
19 |
Correct |
695 ms |
59972 KB |
Output is correct |
20 |
Correct |
377 ms |
49636 KB |
Output is correct |
21 |
Correct |
53 ms |
7936 KB |
Output is correct |
22 |
Correct |
321 ms |
46184 KB |
Output is correct |