#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
const int X = 1005;
vector<int> ed[X], lb;
bool lv[X];
int num;
void init(int N){
lb.assign(N, 0);
for(int i = 0; i < N; ++i) ed[i].clear();
memset(lv, 0, sizeof lv);
num = 0;
}
void dfs(int u, int p){
lv[u] = !lv[p];
if(lv[u]) lb[u] = num++;
for(int v: ed[u]) if(v != p) dfs(v, u);
if(!lv[u]) lb[u] = num++;
}
vector<int> label(int N, int K, vector<int> ar1, vector<int> ar2) {
init(N);
for(int i = 0; i < N - 1; ++i) ed[ar1[i]].emplace_back(ar2[i]), ed[ar2[i]].emplace_back(ar1[i]);
dfs(0, 0);
return lb;
}
int find_next_station(int s, int t, vector<int> c) {
if(c.size() == 1) return c[0];
sort(c.begin(), c.end());
if(c[0] < s){
if(t < c[1] or t > s) return c[0];
return *(upper_bound(c.begin(), c.end(), t) - 1);
} else {
if(t > c[c.size() - 2] or t < s) return c.back();
return *lower_bound(c.begin(), c.end(), t);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
500 ms |
1092 KB |
Output is correct |
2 |
Correct |
532 ms |
992 KB |
Output is correct |
3 |
Correct |
883 ms |
952 KB |
Output is correct |
4 |
Correct |
720 ms |
952 KB |
Output is correct |
5 |
Correct |
666 ms |
952 KB |
Output is correct |
6 |
Correct |
496 ms |
1224 KB |
Output is correct |
7 |
Correct |
546 ms |
1116 KB |
Output is correct |
8 |
Correct |
3 ms |
736 KB |
Output is correct |
9 |
Correct |
6 ms |
864 KB |
Output is correct |
10 |
Correct |
2 ms |
952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
431 ms |
884 KB |
Output is correct |
2 |
Correct |
654 ms |
864 KB |
Output is correct |
3 |
Correct |
1055 ms |
864 KB |
Output is correct |
4 |
Correct |
694 ms |
736 KB |
Output is correct |
5 |
Correct |
650 ms |
836 KB |
Output is correct |
6 |
Correct |
486 ms |
864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
560 ms |
864 KB |
Output is correct |
2 |
Correct |
478 ms |
1088 KB |
Output is correct |
3 |
Correct |
872 ms |
952 KB |
Output is correct |
4 |
Correct |
707 ms |
1040 KB |
Output is correct |
5 |
Correct |
676 ms |
952 KB |
Output is correct |
6 |
Correct |
533 ms |
996 KB |
Output is correct |
7 |
Correct |
516 ms |
1108 KB |
Output is correct |
8 |
Correct |
3 ms |
960 KB |
Output is correct |
9 |
Correct |
5 ms |
864 KB |
Output is correct |
10 |
Correct |
2 ms |
736 KB |
Output is correct |
11 |
Correct |
721 ms |
952 KB |
Output is correct |
12 |
Correct |
538 ms |
1100 KB |
Output is correct |
13 |
Correct |
545 ms |
1120 KB |
Output is correct |
14 |
Correct |
518 ms |
900 KB |
Output is correct |
15 |
Correct |
62 ms |
864 KB |
Output is correct |
16 |
Correct |
70 ms |
948 KB |
Output is correct |
17 |
Correct |
145 ms |
864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1047 ms |
952 KB |
Output is correct |
2 |
Correct |
729 ms |
992 KB |
Output is correct |
3 |
Correct |
683 ms |
864 KB |
Output is correct |
4 |
Correct |
3 ms |
960 KB |
Output is correct |
5 |
Correct |
5 ms |
960 KB |
Output is correct |
6 |
Correct |
2 ms |
864 KB |
Output is correct |
7 |
Correct |
802 ms |
960 KB |
Output is correct |
8 |
Correct |
1012 ms |
952 KB |
Output is correct |
9 |
Correct |
832 ms |
952 KB |
Output is correct |
10 |
Correct |
764 ms |
1024 KB |
Output is correct |
11 |
Correct |
8 ms |
864 KB |
Output is correct |
12 |
Correct |
6 ms |
736 KB |
Output is correct |
13 |
Correct |
6 ms |
864 KB |
Output is correct |
14 |
Correct |
5 ms |
960 KB |
Output is correct |
15 |
Correct |
3 ms |
736 KB |
Output is correct |
16 |
Correct |
656 ms |
864 KB |
Output is correct |
17 |
Correct |
518 ms |
800 KB |
Output is correct |
18 |
Correct |
502 ms |
1080 KB |
Output is correct |
19 |
Correct |
543 ms |
952 KB |
Output is correct |
20 |
Correct |
580 ms |
952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
554 ms |
1088 KB |
Output is correct |
2 |
Correct |
489 ms |
992 KB |
Output is correct |
3 |
Correct |
844 ms |
952 KB |
Output is correct |
4 |
Correct |
647 ms |
952 KB |
Output is correct |
5 |
Correct |
656 ms |
844 KB |
Output is correct |
6 |
Correct |
458 ms |
1100 KB |
Output is correct |
7 |
Correct |
496 ms |
872 KB |
Output is correct |
8 |
Correct |
4 ms |
864 KB |
Output is correct |
9 |
Correct |
6 ms |
736 KB |
Output is correct |
10 |
Correct |
2 ms |
736 KB |
Output is correct |
11 |
Correct |
515 ms |
864 KB |
Output is correct |
12 |
Correct |
603 ms |
892 KB |
Output is correct |
13 |
Correct |
1008 ms |
952 KB |
Output is correct |
14 |
Correct |
784 ms |
864 KB |
Output is correct |
15 |
Correct |
680 ms |
864 KB |
Output is correct |
16 |
Correct |
550 ms |
864 KB |
Output is correct |
17 |
Correct |
757 ms |
952 KB |
Output is correct |
18 |
Correct |
502 ms |
1240 KB |
Output is correct |
19 |
Correct |
490 ms |
1220 KB |
Output is correct |
20 |
Correct |
428 ms |
864 KB |
Output is correct |
21 |
Correct |
70 ms |
864 KB |
Output is correct |
22 |
Correct |
79 ms |
736 KB |
Output is correct |
23 |
Correct |
107 ms |
884 KB |
Output is correct |
24 |
Correct |
7 ms |
736 KB |
Output is correct |
25 |
Correct |
8 ms |
952 KB |
Output is correct |
26 |
Correct |
6 ms |
736 KB |
Output is correct |
27 |
Correct |
5 ms |
736 KB |
Output is correct |
28 |
Correct |
3 ms |
960 KB |
Output is correct |
29 |
Correct |
603 ms |
768 KB |
Output is correct |
30 |
Correct |
560 ms |
952 KB |
Output is correct |
31 |
Correct |
635 ms |
1012 KB |
Output is correct |
32 |
Correct |
547 ms |
864 KB |
Output is correct |
33 |
Correct |
602 ms |
992 KB |
Output is correct |
34 |
Correct |
360 ms |
1096 KB |
Output is correct |
35 |
Correct |
517 ms |
1080 KB |
Output is correct |
36 |
Correct |
598 ms |
1012 KB |
Output is correct |
37 |
Correct |
480 ms |
1124 KB |
Output is correct |
38 |
Correct |
441 ms |
992 KB |
Output is correct |
39 |
Correct |
424 ms |
1120 KB |
Output is correct |
40 |
Correct |
422 ms |
1364 KB |
Output is correct |
41 |
Correct |
442 ms |
1152 KB |
Output is correct |
42 |
Correct |
79 ms |
864 KB |
Output is correct |
43 |
Correct |
116 ms |
1000 KB |
Output is correct |
44 |
Correct |
144 ms |
864 KB |
Output is correct |
45 |
Correct |
199 ms |
992 KB |
Output is correct |
46 |
Correct |
285 ms |
904 KB |
Output is correct |
47 |
Correct |
343 ms |
876 KB |
Output is correct |
48 |
Correct |
62 ms |
1100 KB |
Output is correct |
49 |
Correct |
60 ms |
992 KB |
Output is correct |