#include "stations.h"
#include <vector>
using namespace std;
typedef vector<int> IVec;
void rec(int u, int fa, bool dfs_in, int &clock, const vector<IVec>& G, IVec& L) {
if (dfs_in) L[u] = clock++;
for (int i : G[u])
if (i != fa) rec(i, u, !dfs_in, clock, G, L);
if (!dfs_in) L[u] = clock++;
}
IVec label(int n, int k, IVec u, IVec v) {
IVec L(n);
vector<IVec> G(n, IVec());
for (int i = 0; i < u.size(); i++)
G[u[i]].push_back(v[i]), G[v[i]].push_back(u[i]);
int clock = 0;
rec(0, -1, true, clock, G, L);
return L;
}
int find_next_station(int s, int t, IVec c) {
if (c[0] > s) { // Case 1: s is in InClock. All the neighbors' label > s.
if (t < s || t > c.back()) return c.back(); // t not in this subtree, go to parent.
int v = 0; // t is in this subtree, Pick the smallest ch >= t
return *lower_bound(c.begin(), c.end(), t);
}
if (t < c[0]) // Case 2: node s is in the post_order level.
return c[0]; // t not in subtree
if (t > s) return c[0]; // t not in this subtree, go to the root.
int v = c.size() - 1;
while (c[v] > t) v--;
return c[v];
}
Compilation message
stations.cpp: In function 'IVec label(int, int, IVec, IVec)':
stations.cpp:16:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | for (int i = 0; i < u.size(); i++)
| ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, IVec)':
stations.cpp:26:9: warning: unused variable 'v' [-Wunused-variable]
26 | int v = 0; // t is in this subtree, Pick the smallest ch >= t
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
566 ms |
876 KB |
Output is correct |
2 |
Correct |
608 ms |
884 KB |
Output is correct |
3 |
Correct |
988 ms |
756 KB |
Output is correct |
4 |
Correct |
819 ms |
756 KB |
Output is correct |
5 |
Correct |
699 ms |
756 KB |
Output is correct |
6 |
Correct |
565 ms |
988 KB |
Output is correct |
7 |
Correct |
607 ms |
1008 KB |
Output is correct |
8 |
Correct |
2 ms |
880 KB |
Output is correct |
9 |
Correct |
5 ms |
1008 KB |
Output is correct |
10 |
Correct |
1 ms |
756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
606 ms |
736 KB |
Output is correct |
2 |
Correct |
582 ms |
864 KB |
Output is correct |
3 |
Correct |
1047 ms |
772 KB |
Output is correct |
4 |
Correct |
749 ms |
736 KB |
Output is correct |
5 |
Correct |
621 ms |
756 KB |
Output is correct |
6 |
Correct |
518 ms |
736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
591 ms |
884 KB |
Output is correct |
2 |
Correct |
544 ms |
920 KB |
Output is correct |
3 |
Correct |
1055 ms |
756 KB |
Output is correct |
4 |
Correct |
814 ms |
880 KB |
Output is correct |
5 |
Correct |
648 ms |
756 KB |
Output is correct |
6 |
Correct |
608 ms |
896 KB |
Output is correct |
7 |
Correct |
548 ms |
884 KB |
Output is correct |
8 |
Correct |
3 ms |
756 KB |
Output is correct |
9 |
Correct |
4 ms |
756 KB |
Output is correct |
10 |
Correct |
1 ms |
756 KB |
Output is correct |
11 |
Correct |
593 ms |
1008 KB |
Output is correct |
12 |
Correct |
504 ms |
1012 KB |
Output is correct |
13 |
Correct |
545 ms |
864 KB |
Output is correct |
14 |
Correct |
522 ms |
748 KB |
Output is correct |
15 |
Correct |
66 ms |
884 KB |
Output is correct |
16 |
Correct |
71 ms |
736 KB |
Output is correct |
17 |
Correct |
116 ms |
884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
931 ms |
800 KB |
Output is correct |
2 |
Correct |
727 ms |
1008 KB |
Output is correct |
3 |
Correct |
660 ms |
756 KB |
Output is correct |
4 |
Correct |
2 ms |
756 KB |
Output is correct |
5 |
Correct |
5 ms |
736 KB |
Output is correct |
6 |
Correct |
2 ms |
736 KB |
Output is correct |
7 |
Correct |
619 ms |
736 KB |
Output is correct |
8 |
Correct |
1043 ms |
752 KB |
Output is correct |
9 |
Correct |
741 ms |
756 KB |
Output is correct |
10 |
Correct |
574 ms |
752 KB |
Output is correct |
11 |
Correct |
7 ms |
736 KB |
Output is correct |
12 |
Correct |
6 ms |
736 KB |
Output is correct |
13 |
Correct |
5 ms |
756 KB |
Output is correct |
14 |
Correct |
3 ms |
748 KB |
Output is correct |
15 |
Correct |
2 ms |
888 KB |
Output is correct |
16 |
Correct |
679 ms |
880 KB |
Output is correct |
17 |
Correct |
645 ms |
920 KB |
Output is correct |
18 |
Correct |
656 ms |
756 KB |
Output is correct |
19 |
Correct |
645 ms |
880 KB |
Output is correct |
20 |
Correct |
574 ms |
736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
654 ms |
864 KB |
Output is correct |
2 |
Correct |
473 ms |
884 KB |
Output is correct |
3 |
Correct |
1033 ms |
756 KB |
Output is correct |
4 |
Correct |
714 ms |
748 KB |
Output is correct |
5 |
Correct |
671 ms |
736 KB |
Output is correct |
6 |
Correct |
589 ms |
884 KB |
Output is correct |
7 |
Correct |
462 ms |
756 KB |
Output is correct |
8 |
Correct |
2 ms |
796 KB |
Output is correct |
9 |
Correct |
5 ms |
756 KB |
Output is correct |
10 |
Correct |
1 ms |
880 KB |
Output is correct |
11 |
Correct |
494 ms |
756 KB |
Output is correct |
12 |
Correct |
669 ms |
960 KB |
Output is correct |
13 |
Correct |
1172 ms |
796 KB |
Output is correct |
14 |
Correct |
675 ms |
756 KB |
Output is correct |
15 |
Correct |
689 ms |
756 KB |
Output is correct |
16 |
Correct |
493 ms |
1184 KB |
Output is correct |
17 |
Correct |
622 ms |
756 KB |
Output is correct |
18 |
Correct |
668 ms |
880 KB |
Output is correct |
19 |
Correct |
487 ms |
1100 KB |
Output is correct |
20 |
Correct |
534 ms |
756 KB |
Output is correct |
21 |
Correct |
69 ms |
736 KB |
Output is correct |
22 |
Correct |
74 ms |
788 KB |
Output is correct |
23 |
Correct |
133 ms |
756 KB |
Output is correct |
24 |
Correct |
6 ms |
736 KB |
Output is correct |
25 |
Correct |
6 ms |
756 KB |
Output is correct |
26 |
Correct |
5 ms |
736 KB |
Output is correct |
27 |
Correct |
5 ms |
736 KB |
Output is correct |
28 |
Correct |
2 ms |
736 KB |
Output is correct |
29 |
Correct |
512 ms |
756 KB |
Output is correct |
30 |
Correct |
528 ms |
888 KB |
Output is correct |
31 |
Correct |
504 ms |
880 KB |
Output is correct |
32 |
Correct |
572 ms |
1008 KB |
Output is correct |
33 |
Correct |
482 ms |
880 KB |
Output is correct |
34 |
Correct |
336 ms |
992 KB |
Output is correct |
35 |
Correct |
473 ms |
884 KB |
Output is correct |
36 |
Correct |
483 ms |
1240 KB |
Output is correct |
37 |
Correct |
458 ms |
888 KB |
Output is correct |
38 |
Correct |
474 ms |
736 KB |
Output is correct |
39 |
Correct |
438 ms |
840 KB |
Output is correct |
40 |
Correct |
451 ms |
864 KB |
Output is correct |
41 |
Correct |
516 ms |
884 KB |
Output is correct |
42 |
Correct |
82 ms |
828 KB |
Output is correct |
43 |
Correct |
138 ms |
756 KB |
Output is correct |
44 |
Correct |
127 ms |
756 KB |
Output is correct |
45 |
Correct |
176 ms |
736 KB |
Output is correct |
46 |
Correct |
318 ms |
800 KB |
Output is correct |
47 |
Correct |
349 ms |
764 KB |
Output is correct |
48 |
Correct |
77 ms |
756 KB |
Output is correct |
49 |
Correct |
73 ms |
736 KB |
Output is correct |