#include <bits/stdc++.h>
#include "stations.h"
using namespace std;
typedef vector<int> vi;
#define pb push_back
vi g[2000];
vi ans, sz, used;
int cur;
void dfs1(int u = 0, int p = -1, int d = 0){
for (int v : g[u]){
if (v == p) continue;
dfs1(v, u, d+1);
sz[u] += sz[v] + 1;
}
}
void dfs2(int u = 0, int p = -1, int d = 0){
if (d % 2 == 0){
used[cur] = 1;
ans[u] = cur;
while (used[cur]) cur++;
}else{
used[cur+sz[u]] = 1;
ans[u] = cur+sz[u];
while (used[cur]) cur++;
}
for (int v : g[u]){
if (v == p) continue;
dfs2(v, u, d+1);
}
}
vi label(int n, int k, vi u, vi v) {
cur = 0;
vi answer; answer.resize(n, 0);
ans.resize(n, 0); sz.resize(n, 0); used.resize(n, 0);
for (int i = 0; i < n-1; i++){
g[u[i]].pb(v[i]);
g[v[i]].pb(u[i]);
}
dfs1();
dfs2();
answer = ans;
ans.clear(); sz.clear(); used.clear();
for (int i = 0; i < n; i++) g[i].clear();
return answer;
}
int find_next_station(int s, int t, vi c) {
int C = c.size();
if (C==1) return c[0];
if (s < c[0]){
if (t < s || t >= c[C-1]) return c[C-1];
int ans = s;
for (int i = 0; i < C-1; i++){
if (ans < t && t <= c[i]) return c[i];
ans = c[i];
}
return c[C-1];
}
if (t > s || t <= c[0]) return c[0];
int ans = s;
for (int i = C-1; i > 0; i--){
if (ans > t && t >= c[i]) return c[i];
ans = c[i];
}
return c[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
581 ms |
784 KB |
Output is correct |
2 |
Correct |
501 ms |
784 KB |
Output is correct |
3 |
Correct |
1053 ms |
656 KB |
Output is correct |
4 |
Correct |
844 ms |
660 KB |
Output is correct |
5 |
Correct |
666 ms |
660 KB |
Output is correct |
6 |
Correct |
616 ms |
784 KB |
Output is correct |
7 |
Correct |
511 ms |
660 KB |
Output is correct |
8 |
Correct |
3 ms |
724 KB |
Output is correct |
9 |
Correct |
5 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
547 ms |
656 KB |
Output is correct |
2 |
Correct |
672 ms |
656 KB |
Output is correct |
3 |
Correct |
892 ms |
656 KB |
Output is correct |
4 |
Correct |
754 ms |
668 KB |
Output is correct |
5 |
Correct |
694 ms |
656 KB |
Output is correct |
6 |
Correct |
580 ms |
656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
598 ms |
780 KB |
Output is correct |
2 |
Correct |
558 ms |
788 KB |
Output is correct |
3 |
Correct |
1025 ms |
656 KB |
Output is correct |
4 |
Correct |
772 ms |
656 KB |
Output is correct |
5 |
Correct |
751 ms |
728 KB |
Output is correct |
6 |
Correct |
638 ms |
784 KB |
Output is correct |
7 |
Correct |
516 ms |
784 KB |
Output is correct |
8 |
Correct |
3 ms |
732 KB |
Output is correct |
9 |
Correct |
5 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
612 ms |
660 KB |
Output is correct |
12 |
Correct |
547 ms |
900 KB |
Output is correct |
13 |
Correct |
534 ms |
784 KB |
Output is correct |
14 |
Correct |
547 ms |
656 KB |
Output is correct |
15 |
Correct |
50 ms |
656 KB |
Output is correct |
16 |
Correct |
58 ms |
676 KB |
Output is correct |
17 |
Correct |
142 ms |
656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1186 ms |
656 KB |
Output is correct |
2 |
Correct |
829 ms |
668 KB |
Output is correct |
3 |
Correct |
595 ms |
660 KB |
Output is correct |
4 |
Correct |
3 ms |
724 KB |
Output is correct |
5 |
Correct |
3 ms |
720 KB |
Output is correct |
6 |
Correct |
2 ms |
724 KB |
Output is correct |
7 |
Correct |
643 ms |
656 KB |
Output is correct |
8 |
Correct |
1132 ms |
656 KB |
Output is correct |
9 |
Correct |
659 ms |
664 KB |
Output is correct |
10 |
Correct |
844 ms |
664 KB |
Output is correct |
11 |
Correct |
7 ms |
724 KB |
Output is correct |
12 |
Correct |
7 ms |
728 KB |
Output is correct |
13 |
Correct |
6 ms |
724 KB |
Output is correct |
14 |
Correct |
5 ms |
724 KB |
Output is correct |
15 |
Correct |
3 ms |
732 KB |
Output is correct |
16 |
Correct |
556 ms |
668 KB |
Output is correct |
17 |
Correct |
638 ms |
656 KB |
Output is correct |
18 |
Correct |
589 ms |
656 KB |
Output is correct |
19 |
Correct |
542 ms |
660 KB |
Output is correct |
20 |
Correct |
529 ms |
656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
622 ms |
788 KB |
Output is correct |
2 |
Correct |
494 ms |
784 KB |
Output is correct |
3 |
Correct |
963 ms |
656 KB |
Output is correct |
4 |
Correct |
689 ms |
712 KB |
Output is correct |
5 |
Correct |
670 ms |
668 KB |
Output is correct |
6 |
Correct |
435 ms |
784 KB |
Output is correct |
7 |
Correct |
437 ms |
712 KB |
Output is correct |
8 |
Correct |
3 ms |
724 KB |
Output is correct |
9 |
Correct |
4 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
724 KB |
Output is correct |
11 |
Correct |
536 ms |
656 KB |
Output is correct |
12 |
Correct |
552 ms |
656 KB |
Output is correct |
13 |
Correct |
998 ms |
656 KB |
Output is correct |
14 |
Correct |
690 ms |
656 KB |
Output is correct |
15 |
Correct |
697 ms |
656 KB |
Output is correct |
16 |
Correct |
493 ms |
664 KB |
Output is correct |
17 |
Correct |
632 ms |
656 KB |
Output is correct |
18 |
Correct |
499 ms |
788 KB |
Output is correct |
19 |
Correct |
506 ms |
904 KB |
Output is correct |
20 |
Correct |
532 ms |
664 KB |
Output is correct |
21 |
Correct |
62 ms |
684 KB |
Output is correct |
22 |
Correct |
78 ms |
688 KB |
Output is correct |
23 |
Correct |
128 ms |
656 KB |
Output is correct |
24 |
Correct |
6 ms |
724 KB |
Output is correct |
25 |
Correct |
8 ms |
676 KB |
Output is correct |
26 |
Correct |
6 ms |
724 KB |
Output is correct |
27 |
Correct |
6 ms |
724 KB |
Output is correct |
28 |
Correct |
2 ms |
724 KB |
Output is correct |
29 |
Correct |
499 ms |
656 KB |
Output is correct |
30 |
Correct |
600 ms |
660 KB |
Output is correct |
31 |
Correct |
649 ms |
656 KB |
Output is correct |
32 |
Correct |
536 ms |
664 KB |
Output is correct |
33 |
Correct |
690 ms |
656 KB |
Output is correct |
34 |
Correct |
409 ms |
832 KB |
Output is correct |
35 |
Correct |
411 ms |
792 KB |
Output is correct |
36 |
Correct |
492 ms |
784 KB |
Output is correct |
37 |
Correct |
505 ms |
780 KB |
Output is correct |
38 |
Correct |
560 ms |
660 KB |
Output is correct |
39 |
Correct |
501 ms |
656 KB |
Output is correct |
40 |
Correct |
522 ms |
780 KB |
Output is correct |
41 |
Correct |
542 ms |
660 KB |
Output is correct |
42 |
Correct |
70 ms |
656 KB |
Output is correct |
43 |
Correct |
128 ms |
684 KB |
Output is correct |
44 |
Correct |
146 ms |
656 KB |
Output is correct |
45 |
Correct |
155 ms |
792 KB |
Output is correct |
46 |
Correct |
342 ms |
656 KB |
Output is correct |
47 |
Correct |
324 ms |
656 KB |
Output is correct |
48 |
Correct |
71 ms |
804 KB |
Output is correct |
49 |
Correct |
63 ms |
940 KB |
Output is correct |