#include "stations.h"
#include <vector>
#include <cassert>
#include <cmath>
#include <algorithm>
namespace std {
template<class Fun>
class y_combinator_result {
Fun fun_;
public:
template<class T>
explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
template<class ...Args>
decltype(auto) operator()(Args &&...args) {
return fun_(std::ref(*this), std::forward<Args>(args)...);
}
};
template<class Fun>
decltype(auto) y_combinator(Fun &&fun) {
return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}
} // namespace std
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;
std::y_combinator([&](auto self, int cur, int prv, bool dir) -> void {
if (!dir) {
labels[cur] = cur_idx++;
}
for (int nxt : adj[cur]) {
if (nxt == prv) continue;
self(nxt, cur, !dir);
}
if (dir) {
labels[cur] = 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[0] < S) {
S = -S;
T = -T;
for (int& c : C) c = -c;
}
assert(C[0] > S);
int par = *std::max_element(C.begin(), C.end());
if (T < S || T >= par) {
return abs(par);
}
int ans = par;
for (int c : C) {
if (c >= T) ans = std::min(ans, c);
}
return abs(ans);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
606 ms |
976 KB |
Output is correct |
2 |
Correct |
557 ms |
1024 KB |
Output is correct |
3 |
Correct |
1107 ms |
640 KB |
Output is correct |
4 |
Correct |
805 ms |
740 KB |
Output is correct |
5 |
Correct |
652 ms |
640 KB |
Output is correct |
6 |
Correct |
499 ms |
1016 KB |
Output is correct |
7 |
Correct |
607 ms |
888 KB |
Output is correct |
8 |
Correct |
3 ms |
640 KB |
Output is correct |
9 |
Correct |
6 ms |
640 KB |
Output is correct |
10 |
Correct |
2 ms |
780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
657 ms |
896 KB |
Output is correct |
2 |
Correct |
604 ms |
888 KB |
Output is correct |
3 |
Correct |
1173 ms |
740 KB |
Output is correct |
4 |
Correct |
967 ms |
872 KB |
Output is correct |
5 |
Correct |
748 ms |
748 KB |
Output is correct |
6 |
Correct |
514 ms |
896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
640 ms |
1008 KB |
Output is correct |
2 |
Correct |
462 ms |
1008 KB |
Output is correct |
3 |
Correct |
1053 ms |
860 KB |
Output is correct |
4 |
Correct |
697 ms |
640 KB |
Output is correct |
5 |
Correct |
693 ms |
776 KB |
Output is correct |
6 |
Correct |
627 ms |
1016 KB |
Output is correct |
7 |
Correct |
606 ms |
996 KB |
Output is correct |
8 |
Correct |
3 ms |
640 KB |
Output is correct |
9 |
Correct |
4 ms |
656 KB |
Output is correct |
10 |
Correct |
1 ms |
652 KB |
Output is correct |
11 |
Correct |
661 ms |
904 KB |
Output is correct |
12 |
Correct |
597 ms |
1024 KB |
Output is correct |
13 |
Correct |
635 ms |
1024 KB |
Output is correct |
14 |
Correct |
573 ms |
908 KB |
Output is correct |
15 |
Correct |
60 ms |
776 KB |
Output is correct |
16 |
Correct |
80 ms |
768 KB |
Output is correct |
17 |
Correct |
108 ms |
832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1029 ms |
736 KB |
Output is correct |
2 |
Correct |
730 ms |
780 KB |
Output is correct |
3 |
Correct |
751 ms |
768 KB |
Output is correct |
4 |
Correct |
2 ms |
640 KB |
Output is correct |
5 |
Correct |
6 ms |
768 KB |
Output is correct |
6 |
Correct |
1 ms |
768 KB |
Output is correct |
7 |
Correct |
718 ms |
640 KB |
Output is correct |
8 |
Correct |
1059 ms |
640 KB |
Output is correct |
9 |
Correct |
713 ms |
640 KB |
Output is correct |
10 |
Correct |
690 ms |
768 KB |
Output is correct |
11 |
Correct |
6 ms |
640 KB |
Output is correct |
12 |
Correct |
7 ms |
640 KB |
Output is correct |
13 |
Correct |
4 ms |
768 KB |
Output is correct |
14 |
Correct |
6 ms |
640 KB |
Output is correct |
15 |
Correct |
2 ms |
768 KB |
Output is correct |
16 |
Correct |
588 ms |
916 KB |
Output is correct |
17 |
Correct |
622 ms |
768 KB |
Output is correct |
18 |
Correct |
704 ms |
640 KB |
Output is correct |
19 |
Correct |
613 ms |
656 KB |
Output is correct |
20 |
Correct |
549 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
704 ms |
952 KB |
Output is correct |
2 |
Correct |
638 ms |
984 KB |
Output is correct |
3 |
Correct |
894 ms |
640 KB |
Output is correct |
4 |
Correct |
738 ms |
744 KB |
Output is correct |
5 |
Correct |
629 ms |
640 KB |
Output is correct |
6 |
Correct |
511 ms |
1024 KB |
Output is correct |
7 |
Correct |
562 ms |
1032 KB |
Output is correct |
8 |
Correct |
3 ms |
768 KB |
Output is correct |
9 |
Correct |
4 ms |
832 KB |
Output is correct |
10 |
Correct |
1 ms |
640 KB |
Output is correct |
11 |
Correct |
555 ms |
760 KB |
Output is correct |
12 |
Correct |
681 ms |
892 KB |
Output is correct |
13 |
Correct |
1038 ms |
640 KB |
Output is correct |
14 |
Correct |
775 ms |
656 KB |
Output is correct |
15 |
Correct |
693 ms |
652 KB |
Output is correct |
16 |
Correct |
553 ms |
752 KB |
Output is correct |
17 |
Correct |
621 ms |
768 KB |
Output is correct |
18 |
Correct |
432 ms |
860 KB |
Output is correct |
19 |
Correct |
618 ms |
1144 KB |
Output is correct |
20 |
Correct |
477 ms |
768 KB |
Output is correct |
21 |
Correct |
80 ms |
640 KB |
Output is correct |
22 |
Correct |
115 ms |
800 KB |
Output is correct |
23 |
Correct |
148 ms |
744 KB |
Output is correct |
24 |
Correct |
4 ms |
800 KB |
Output is correct |
25 |
Correct |
8 ms |
768 KB |
Output is correct |
26 |
Correct |
4 ms |
768 KB |
Output is correct |
27 |
Correct |
4 ms |
776 KB |
Output is correct |
28 |
Correct |
1 ms |
640 KB |
Output is correct |
29 |
Correct |
563 ms |
640 KB |
Output is correct |
30 |
Correct |
660 ms |
640 KB |
Output is correct |
31 |
Correct |
747 ms |
768 KB |
Output is correct |
32 |
Correct |
648 ms |
640 KB |
Output is correct |
33 |
Correct |
528 ms |
768 KB |
Output is correct |
34 |
Correct |
369 ms |
768 KB |
Output is correct |
35 |
Correct |
559 ms |
1004 KB |
Output is correct |
36 |
Correct |
589 ms |
880 KB |
Output is correct |
37 |
Correct |
538 ms |
1016 KB |
Output is correct |
38 |
Correct |
549 ms |
844 KB |
Output is correct |
39 |
Correct |
489 ms |
848 KB |
Output is correct |
40 |
Correct |
556 ms |
768 KB |
Output is correct |
41 |
Correct |
604 ms |
844 KB |
Output is correct |
42 |
Correct |
65 ms |
780 KB |
Output is correct |
43 |
Correct |
155 ms |
948 KB |
Output is correct |
44 |
Correct |
178 ms |
768 KB |
Output is correct |
45 |
Correct |
217 ms |
792 KB |
Output is correct |
46 |
Correct |
387 ms |
768 KB |
Output is correct |
47 |
Correct |
328 ms |
896 KB |
Output is correct |
48 |
Correct |
74 ms |
768 KB |
Output is correct |
49 |
Correct |
62 ms |
776 KB |
Output is correct |