#include "stations.h"
#include <vector>
#include <cassert>
#include <cmath>
#include <algorithm>
namespace {
void do_label(const std::vector<std::vector<int>>& adj, std::vector<int>& labels, int& cur_idx, int cur, int prv, bool dir) {
if (!dir) {
labels[cur] = cur_idx++;
}
for (int nxt : adj[cur]) {
if (nxt == prv) continue;
do_label(adj, labels, cur_idx, nxt, cur, !dir);
}
if (dir) {
labels[cur] = cur_idx++;
}
}
}
std::vector<int> label(int N, int K, std::vector<int> U, std::vector<int> V) {
std::vector<std::vector<int>> adj(N);
for (int e = 0; e < N-1; e++) {
adj[U[e]].push_back(V[e]);
adj[V[e]].push_back(U[e]);
}
std::vector<int> labels(N);
int cur_idx = 0;
do_label(adj, labels, cur_idx, 0, -1, false);
assert(cur_idx-1 <= K);
return labels;
}
int find_next_station(int S, int T, std::vector<int> C) {
assert(S != T);
assert(!C.empty());
if (C.front() < S) {
if (T > S || T <= C.front()) return C.front();
auto it = --std::upper_bound(C.begin(), C.end(), T);
return *it;
} else {
if (T < S || T >= C.back()) return C.back();
auto it = std::lower_bound(C.begin(), C.end(), T);
return *it;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
745 ms |
1024 KB |
Output is correct |
2 |
Correct |
520 ms |
928 KB |
Output is correct |
3 |
Correct |
1085 ms |
640 KB |
Output is correct |
4 |
Correct |
780 ms |
800 KB |
Output is correct |
5 |
Correct |
761 ms |
776 KB |
Output is correct |
6 |
Correct |
505 ms |
1024 KB |
Output is correct |
7 |
Correct |
579 ms |
896 KB |
Output is correct |
8 |
Correct |
3 ms |
640 KB |
Output is correct |
9 |
Correct |
7 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
517 ms |
880 KB |
Output is correct |
2 |
Correct |
839 ms |
768 KB |
Output is correct |
3 |
Correct |
1053 ms |
768 KB |
Output is correct |
4 |
Correct |
744 ms |
656 KB |
Output is correct |
5 |
Correct |
801 ms |
640 KB |
Output is correct |
6 |
Correct |
619 ms |
740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
548 ms |
1044 KB |
Output is correct |
2 |
Correct |
666 ms |
988 KB |
Output is correct |
3 |
Correct |
1134 ms |
640 KB |
Output is correct |
4 |
Correct |
664 ms |
744 KB |
Output is correct |
5 |
Correct |
639 ms |
640 KB |
Output is correct |
6 |
Correct |
561 ms |
1008 KB |
Output is correct |
7 |
Correct |
531 ms |
768 KB |
Output is correct |
8 |
Correct |
3 ms |
640 KB |
Output is correct |
9 |
Correct |
3 ms |
768 KB |
Output is correct |
10 |
Correct |
1 ms |
640 KB |
Output is correct |
11 |
Correct |
641 ms |
744 KB |
Output is correct |
12 |
Correct |
592 ms |
1024 KB |
Output is correct |
13 |
Correct |
587 ms |
1008 KB |
Output is correct |
14 |
Correct |
522 ms |
768 KB |
Output is correct |
15 |
Correct |
74 ms |
812 KB |
Output is correct |
16 |
Correct |
73 ms |
768 KB |
Output is correct |
17 |
Correct |
151 ms |
904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1087 ms |
768 KB |
Output is correct |
2 |
Correct |
768 ms |
740 KB |
Output is correct |
3 |
Correct |
639 ms |
640 KB |
Output is correct |
4 |
Correct |
3 ms |
768 KB |
Output is correct |
5 |
Correct |
4 ms |
656 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
731 ms |
876 KB |
Output is correct |
8 |
Correct |
1154 ms |
788 KB |
Output is correct |
9 |
Correct |
723 ms |
640 KB |
Output is correct |
10 |
Correct |
736 ms |
1008 KB |
Output is correct |
11 |
Correct |
7 ms |
640 KB |
Output is correct |
12 |
Correct |
7 ms |
768 KB |
Output is correct |
13 |
Correct |
6 ms |
768 KB |
Output is correct |
14 |
Correct |
4 ms |
640 KB |
Output is correct |
15 |
Correct |
1 ms |
800 KB |
Output is correct |
16 |
Correct |
698 ms |
880 KB |
Output is correct |
17 |
Correct |
693 ms |
768 KB |
Output is correct |
18 |
Correct |
602 ms |
768 KB |
Output is correct |
19 |
Correct |
631 ms |
868 KB |
Output is correct |
20 |
Correct |
647 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
748 ms |
968 KB |
Output is correct |
2 |
Correct |
542 ms |
1016 KB |
Output is correct |
3 |
Correct |
1033 ms |
640 KB |
Output is correct |
4 |
Correct |
887 ms |
640 KB |
Output is correct |
5 |
Correct |
640 ms |
660 KB |
Output is correct |
6 |
Correct |
561 ms |
832 KB |
Output is correct |
7 |
Correct |
534 ms |
792 KB |
Output is correct |
8 |
Correct |
4 ms |
640 KB |
Output is correct |
9 |
Correct |
6 ms |
656 KB |
Output is correct |
10 |
Correct |
0 ms |
640 KB |
Output is correct |
11 |
Correct |
584 ms |
888 KB |
Output is correct |
12 |
Correct |
699 ms |
780 KB |
Output is correct |
13 |
Correct |
997 ms |
736 KB |
Output is correct |
14 |
Correct |
862 ms |
672 KB |
Output is correct |
15 |
Correct |
603 ms |
640 KB |
Output is correct |
16 |
Correct |
467 ms |
768 KB |
Output is correct |
17 |
Correct |
753 ms |
640 KB |
Output is correct |
18 |
Correct |
560 ms |
976 KB |
Output is correct |
19 |
Correct |
655 ms |
1024 KB |
Output is correct |
20 |
Correct |
556 ms |
752 KB |
Output is correct |
21 |
Correct |
83 ms |
768 KB |
Output is correct |
22 |
Correct |
88 ms |
768 KB |
Output is correct |
23 |
Correct |
128 ms |
768 KB |
Output is correct |
24 |
Correct |
8 ms |
640 KB |
Output is correct |
25 |
Correct |
8 ms |
768 KB |
Output is correct |
26 |
Correct |
4 ms |
640 KB |
Output is correct |
27 |
Correct |
3 ms |
640 KB |
Output is correct |
28 |
Correct |
1 ms |
640 KB |
Output is correct |
29 |
Correct |
577 ms |
640 KB |
Output is correct |
30 |
Correct |
829 ms |
740 KB |
Output is correct |
31 |
Correct |
574 ms |
640 KB |
Output is correct |
32 |
Correct |
652 ms |
652 KB |
Output is correct |
33 |
Correct |
550 ms |
1012 KB |
Output is correct |
34 |
Correct |
333 ms |
1024 KB |
Output is correct |
35 |
Correct |
607 ms |
1024 KB |
Output is correct |
36 |
Correct |
552 ms |
976 KB |
Output is correct |
37 |
Correct |
625 ms |
832 KB |
Output is correct |
38 |
Correct |
616 ms |
828 KB |
Output is correct |
39 |
Correct |
685 ms |
920 KB |
Output is correct |
40 |
Correct |
505 ms |
760 KB |
Output is correct |
41 |
Correct |
562 ms |
852 KB |
Output is correct |
42 |
Correct |
92 ms |
768 KB |
Output is correct |
43 |
Correct |
130 ms |
768 KB |
Output is correct |
44 |
Correct |
209 ms |
768 KB |
Output is correct |
45 |
Correct |
178 ms |
768 KB |
Output is correct |
46 |
Correct |
407 ms |
776 KB |
Output is correct |
47 |
Correct |
338 ms |
768 KB |
Output is correct |
48 |
Correct |
77 ms |
904 KB |
Output is correct |
49 |
Correct |
77 ms |
768 KB |
Output is correct |