#include "stations.h"
#include <algorithm>
#include <vector>
using namespace std;
vector<vector<int>> g;
vector<int> intime, outtime, depth;
int time;
void dfs(int v) {
intime[v] = time++;
for (int x : g[v])
if (intime[x] == -1) {
depth[x] = depth[v] + 1;
dfs(x);
}
outtime[v] = time++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
g.assign(n, {});
intime.assign(n, -1);
outtime.assign(n, -1);
depth.assign(n, 0);
for (int i = 0; i < n - 1; i++) {
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
time = 0;
dfs(0);
vector<int> labels(n);
for (int i = 0; i < n; i++) {
labels[i] = depth[i] % 2 == 0 ? intime[i] / 2 : outtime[i] / 2;
}
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
// sort(c.begin(), c.end()); they are already sorted
if (s < c[0]) {
// s: intime, c[i]: outtime, c.back(): parent of s
// subtree of s: s < t <= c[c.size() - 2],
// except if s==0 (root), but the below code is correct for it, too
if (t < s || c.size() == 1 || t > c[c.size() - 2])
return c.back();
return *lower_bound(c.begin(), c.end(), t);
} else {
// s: outtime, c[i]: intime, c[0]: parent of s
// subtree of s: c[1] <= t < s
if (t > s || c.size() == 1 || t < c[1])
return c[0];
return *(upper_bound(c.begin(), c.end(), t) - 1);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
718 ms |
776 KB |
Output is correct |
2 |
Correct |
426 ms |
1024 KB |
Output is correct |
3 |
Correct |
911 ms |
640 KB |
Output is correct |
4 |
Correct |
689 ms |
640 KB |
Output is correct |
5 |
Correct |
785 ms |
656 KB |
Output is correct |
6 |
Correct |
481 ms |
768 KB |
Output is correct |
7 |
Correct |
558 ms |
792 KB |
Output is correct |
8 |
Correct |
3 ms |
664 KB |
Output is correct |
9 |
Correct |
4 ms |
640 KB |
Output is correct |
10 |
Correct |
0 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
507 ms |
768 KB |
Output is correct |
2 |
Correct |
614 ms |
824 KB |
Output is correct |
3 |
Correct |
1097 ms |
640 KB |
Output is correct |
4 |
Correct |
658 ms |
640 KB |
Output is correct |
5 |
Correct |
802 ms |
680 KB |
Output is correct |
6 |
Correct |
498 ms |
900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
583 ms |
960 KB |
Output is correct |
2 |
Correct |
464 ms |
1008 KB |
Output is correct |
3 |
Correct |
867 ms |
736 KB |
Output is correct |
4 |
Correct |
716 ms |
640 KB |
Output is correct |
5 |
Correct |
613 ms |
744 KB |
Output is correct |
6 |
Correct |
604 ms |
768 KB |
Output is correct |
7 |
Correct |
610 ms |
760 KB |
Output is correct |
8 |
Correct |
3 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
2 ms |
724 KB |
Output is correct |
11 |
Correct |
601 ms |
640 KB |
Output is correct |
12 |
Correct |
586 ms |
836 KB |
Output is correct |
13 |
Correct |
518 ms |
960 KB |
Output is correct |
14 |
Correct |
426 ms |
768 KB |
Output is correct |
15 |
Correct |
57 ms |
640 KB |
Output is correct |
16 |
Correct |
59 ms |
768 KB |
Output is correct |
17 |
Correct |
111 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
861 ms |
736 KB |
Output is correct |
2 |
Correct |
729 ms |
640 KB |
Output is correct |
3 |
Correct |
684 ms |
640 KB |
Output is correct |
4 |
Correct |
3 ms |
640 KB |
Output is correct |
5 |
Correct |
4 ms |
640 KB |
Output is correct |
6 |
Correct |
2 ms |
640 KB |
Output is correct |
7 |
Correct |
634 ms |
640 KB |
Output is correct |
8 |
Correct |
1210 ms |
640 KB |
Output is correct |
9 |
Correct |
726 ms |
640 KB |
Output is correct |
10 |
Correct |
828 ms |
640 KB |
Output is correct |
11 |
Correct |
5 ms |
640 KB |
Output is correct |
12 |
Correct |
6 ms |
640 KB |
Output is correct |
13 |
Correct |
6 ms |
656 KB |
Output is correct |
14 |
Correct |
5 ms |
672 KB |
Output is correct |
15 |
Correct |
1 ms |
640 KB |
Output is correct |
16 |
Correct |
679 ms |
656 KB |
Output is correct |
17 |
Correct |
686 ms |
640 KB |
Output is correct |
18 |
Correct |
593 ms |
640 KB |
Output is correct |
19 |
Correct |
621 ms |
640 KB |
Output is correct |
20 |
Correct |
609 ms |
656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
707 ms |
1008 KB |
Output is correct |
2 |
Correct |
705 ms |
1008 KB |
Output is correct |
3 |
Correct |
1152 ms |
640 KB |
Output is correct |
4 |
Correct |
854 ms |
640 KB |
Output is correct |
5 |
Correct |
738 ms |
640 KB |
Output is correct |
6 |
Correct |
693 ms |
760 KB |
Output is correct |
7 |
Correct |
625 ms |
768 KB |
Output is correct |
8 |
Correct |
3 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
640 KB |
Output is correct |
11 |
Correct |
467 ms |
780 KB |
Output is correct |
12 |
Correct |
760 ms |
768 KB |
Output is correct |
13 |
Correct |
1019 ms |
744 KB |
Output is correct |
14 |
Correct |
771 ms |
652 KB |
Output is correct |
15 |
Correct |
542 ms |
640 KB |
Output is correct |
16 |
Correct |
397 ms |
768 KB |
Output is correct |
17 |
Correct |
790 ms |
640 KB |
Output is correct |
18 |
Correct |
588 ms |
768 KB |
Output is correct |
19 |
Correct |
549 ms |
788 KB |
Output is correct |
20 |
Correct |
607 ms |
768 KB |
Output is correct |
21 |
Correct |
72 ms |
652 KB |
Output is correct |
22 |
Correct |
95 ms |
848 KB |
Output is correct |
23 |
Correct |
134 ms |
768 KB |
Output is correct |
24 |
Correct |
6 ms |
656 KB |
Output is correct |
25 |
Correct |
3 ms |
640 KB |
Output is correct |
26 |
Correct |
4 ms |
656 KB |
Output is correct |
27 |
Correct |
5 ms |
640 KB |
Output is correct |
28 |
Correct |
2 ms |
640 KB |
Output is correct |
29 |
Correct |
640 ms |
736 KB |
Output is correct |
30 |
Correct |
725 ms |
648 KB |
Output is correct |
31 |
Correct |
722 ms |
736 KB |
Output is correct |
32 |
Correct |
492 ms |
664 KB |
Output is correct |
33 |
Correct |
485 ms |
748 KB |
Output is correct |
34 |
Correct |
354 ms |
1024 KB |
Output is correct |
35 |
Correct |
439 ms |
768 KB |
Output is correct |
36 |
Correct |
466 ms |
1008 KB |
Output is correct |
37 |
Correct |
638 ms |
784 KB |
Output is correct |
38 |
Correct |
473 ms |
772 KB |
Output is correct |
39 |
Correct |
469 ms |
800 KB |
Output is correct |
40 |
Correct |
480 ms |
768 KB |
Output is correct |
41 |
Correct |
487 ms |
768 KB |
Output is correct |
42 |
Correct |
83 ms |
768 KB |
Output is correct |
43 |
Correct |
146 ms |
768 KB |
Output is correct |
44 |
Correct |
125 ms |
768 KB |
Output is correct |
45 |
Correct |
225 ms |
976 KB |
Output is correct |
46 |
Correct |
301 ms |
768 KB |
Output is correct |
47 |
Correct |
324 ms |
768 KB |
Output is correct |
48 |
Correct |
63 ms |
788 KB |
Output is correct |
49 |
Correct |
60 ms |
1028 KB |
Output is correct |