#include <bits/stdc++.h>
#include "stations.h"
template <class T>
using Vec = std::vector<T>;
Vec<int> label(int n, int k, Vec<int> u, Vec<int> v) {
Vec<Vec<int>> graph(n);
for (int i = 0; i < n - 1; ++i) {
graph[u[i]].push_back(v[i]);
graph[v[i]].push_back(u[i]);
}
int time = 0;
Vec<int> ret(n);
auto dfs = [&](auto dfs, const int u, const int p, const int d) -> void {
const auto in = time++;
for (const auto v: graph[u]) {
if (v != p) {
dfs(dfs, v, u, d + 1);
}
}
const auto out = time++;
ret[u] = (d % 2 == 0 ? in : out) / 2;
};
dfs(dfs, 0, -1, 0);
return ret;
}
int find_next_station(int s, int t, Vec<int> c) {
if (c.size() == 1) {
return c[0];
}
std::sort(c.begin(), c.end());
if (s == 0) {
return *std::lower_bound(c.begin(), c.end(), t);
}
if (s < c.front()) {
const auto p = c.back();
c.pop_back();
if (s < t && t <= c.back()) {
return *std::lower_bound(c.begin(), c.end(), t);
}
else {
return p;
}
}
else {
const auto p = c.front();
c.erase(c.begin());
if (c.front() <= t && t < s) {
return *std::prev(std::upper_bound(c.begin(), c.end(), t));
}
else {
return p;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
596 ms |
1044 KB |
Output is correct |
2 |
Correct |
558 ms |
944 KB |
Output is correct |
3 |
Correct |
999 ms |
756 KB |
Output is correct |
4 |
Correct |
688 ms |
868 KB |
Output is correct |
5 |
Correct |
741 ms |
868 KB |
Output is correct |
6 |
Correct |
501 ms |
884 KB |
Output is correct |
7 |
Correct |
436 ms |
884 KB |
Output is correct |
8 |
Correct |
3 ms |
876 KB |
Output is correct |
9 |
Correct |
5 ms |
756 KB |
Output is correct |
10 |
Correct |
2 ms |
756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
440 ms |
736 KB |
Output is correct |
2 |
Correct |
480 ms |
1208 KB |
Output is correct |
3 |
Correct |
956 ms |
756 KB |
Output is correct |
4 |
Correct |
650 ms |
756 KB |
Output is correct |
5 |
Correct |
609 ms |
884 KB |
Output is correct |
6 |
Correct |
443 ms |
892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
499 ms |
1188 KB |
Output is correct |
2 |
Correct |
456 ms |
948 KB |
Output is correct |
3 |
Correct |
836 ms |
868 KB |
Output is correct |
4 |
Correct |
636 ms |
868 KB |
Output is correct |
5 |
Correct |
553 ms |
868 KB |
Output is correct |
6 |
Correct |
497 ms |
948 KB |
Output is correct |
7 |
Correct |
450 ms |
1012 KB |
Output is correct |
8 |
Correct |
2 ms |
916 KB |
Output is correct |
9 |
Correct |
6 ms |
868 KB |
Output is correct |
10 |
Correct |
2 ms |
1060 KB |
Output is correct |
11 |
Correct |
658 ms |
756 KB |
Output is correct |
12 |
Correct |
533 ms |
992 KB |
Output is correct |
13 |
Correct |
494 ms |
884 KB |
Output is correct |
14 |
Correct |
520 ms |
756 KB |
Output is correct |
15 |
Correct |
43 ms |
756 KB |
Output is correct |
16 |
Correct |
75 ms |
864 KB |
Output is correct |
17 |
Correct |
134 ms |
788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
995 ms |
756 KB |
Output is correct |
2 |
Correct |
724 ms |
756 KB |
Output is correct |
3 |
Correct |
609 ms |
756 KB |
Output is correct |
4 |
Correct |
3 ms |
876 KB |
Output is correct |
5 |
Correct |
5 ms |
756 KB |
Output is correct |
6 |
Correct |
2 ms |
776 KB |
Output is correct |
7 |
Correct |
682 ms |
884 KB |
Output is correct |
8 |
Correct |
935 ms |
868 KB |
Output is correct |
9 |
Correct |
728 ms |
756 KB |
Output is correct |
10 |
Correct |
645 ms |
868 KB |
Output is correct |
11 |
Correct |
7 ms |
884 KB |
Output is correct |
12 |
Correct |
7 ms |
916 KB |
Output is correct |
13 |
Correct |
6 ms |
736 KB |
Output is correct |
14 |
Correct |
4 ms |
736 KB |
Output is correct |
15 |
Correct |
2 ms |
736 KB |
Output is correct |
16 |
Correct |
488 ms |
884 KB |
Output is correct |
17 |
Correct |
513 ms |
1060 KB |
Output is correct |
18 |
Correct |
611 ms |
868 KB |
Output is correct |
19 |
Correct |
568 ms |
756 KB |
Output is correct |
20 |
Correct |
494 ms |
868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
530 ms |
884 KB |
Output is correct |
2 |
Correct |
482 ms |
1084 KB |
Output is correct |
3 |
Correct |
906 ms |
868 KB |
Output is correct |
4 |
Correct |
629 ms |
996 KB |
Output is correct |
5 |
Correct |
740 ms |
996 KB |
Output is correct |
6 |
Correct |
480 ms |
864 KB |
Output is correct |
7 |
Correct |
484 ms |
864 KB |
Output is correct |
8 |
Correct |
3 ms |
916 KB |
Output is correct |
9 |
Correct |
4 ms |
736 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
11 |
Correct |
519 ms |
884 KB |
Output is correct |
12 |
Correct |
677 ms |
756 KB |
Output is correct |
13 |
Correct |
951 ms |
868 KB |
Output is correct |
14 |
Correct |
697 ms |
868 KB |
Output is correct |
15 |
Correct |
612 ms |
756 KB |
Output is correct |
16 |
Correct |
498 ms |
796 KB |
Output is correct |
17 |
Correct |
619 ms |
868 KB |
Output is correct |
18 |
Correct |
632 ms |
1108 KB |
Output is correct |
19 |
Correct |
614 ms |
1140 KB |
Output is correct |
20 |
Correct |
441 ms |
792 KB |
Output is correct |
21 |
Correct |
57 ms |
756 KB |
Output is correct |
22 |
Correct |
78 ms |
816 KB |
Output is correct |
23 |
Correct |
117 ms |
736 KB |
Output is correct |
24 |
Correct |
6 ms |
756 KB |
Output is correct |
25 |
Correct |
6 ms |
736 KB |
Output is correct |
26 |
Correct |
6 ms |
876 KB |
Output is correct |
27 |
Correct |
4 ms |
756 KB |
Output is correct |
28 |
Correct |
2 ms |
736 KB |
Output is correct |
29 |
Correct |
613 ms |
736 KB |
Output is correct |
30 |
Correct |
515 ms |
756 KB |
Output is correct |
31 |
Correct |
560 ms |
868 KB |
Output is correct |
32 |
Correct |
619 ms |
756 KB |
Output is correct |
33 |
Correct |
500 ms |
736 KB |
Output is correct |
34 |
Correct |
312 ms |
1140 KB |
Output is correct |
35 |
Correct |
429 ms |
996 KB |
Output is correct |
36 |
Correct |
524 ms |
884 KB |
Output is correct |
37 |
Correct |
425 ms |
1004 KB |
Output is correct |
38 |
Correct |
462 ms |
1004 KB |
Output is correct |
39 |
Correct |
553 ms |
1004 KB |
Output is correct |
40 |
Correct |
448 ms |
1004 KB |
Output is correct |
41 |
Correct |
459 ms |
992 KB |
Output is correct |
42 |
Correct |
76 ms |
808 KB |
Output is correct |
43 |
Correct |
107 ms |
736 KB |
Output is correct |
44 |
Correct |
127 ms |
756 KB |
Output is correct |
45 |
Correct |
148 ms |
736 KB |
Output is correct |
46 |
Correct |
344 ms |
736 KB |
Output is correct |
47 |
Correct |
272 ms |
1000 KB |
Output is correct |
48 |
Correct |
65 ms |
756 KB |
Output is correct |
49 |
Correct |
60 ms |
892 KB |
Output is correct |