#include <bits/stdc++.h>
using namespace std;
vector<int> st, en, d;
vector<vector<int>> adj;
int t;
void dfs(int curr, int par) {
st[curr] = t++;
for(int next : adj[curr]) {
if(next == par) continue;
d[next] = d[curr] + 1;
dfs(next, curr);
}
en[curr] = t++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
adj.clear(), st.clear(), en.clear(), d.clear();
adj.resize(n);
st.resize(n);
en.resize(n);
d.resize(n);
for(int i = 0; i < n - 1; i++) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
vector<int> ans(n);
t = 0;
dfs(0, -1);
for(int i = 0; i < n; i++) {
if(d[i] % 2 == 0) ans[i] = st[i] / 2;
else ans[i] = en[i] / 2;
}
return ans;
}
int find_next_station(int s, int t, vector<int> c) {
if(c[0] < s) {
for(int i = (int) c.size() - 1; i >= 1; i--) {
if(t >= c[i] && t <= s) return c[i];
}
return c[0];
}
else {
for(int i = 0; i < (int) c.size() - 1; i++) {
if(t <= c[i] && t >= s) return c[i];
}
return c.back();
}
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
712 ms |
528 KB |
Output is correct |
2 |
Correct |
556 ms |
616 KB |
Output is correct |
3 |
Correct |
1095 ms |
400 KB |
Output is correct |
4 |
Correct |
978 ms |
400 KB |
Output is correct |
5 |
Correct |
806 ms |
488 KB |
Output is correct |
6 |
Correct |
511 ms |
600 KB |
Output is correct |
7 |
Correct |
489 ms |
528 KB |
Output is correct |
8 |
Correct |
4 ms |
468 KB |
Output is correct |
9 |
Correct |
6 ms |
472 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
533 ms |
612 KB |
Output is correct |
2 |
Correct |
588 ms |
480 KB |
Output is correct |
3 |
Correct |
943 ms |
400 KB |
Output is correct |
4 |
Correct |
820 ms |
400 KB |
Output is correct |
5 |
Correct |
645 ms |
492 KB |
Output is correct |
6 |
Correct |
545 ms |
528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
615 ms |
644 KB |
Output is correct |
2 |
Correct |
547 ms |
604 KB |
Output is correct |
3 |
Correct |
933 ms |
528 KB |
Output is correct |
4 |
Correct |
899 ms |
400 KB |
Output is correct |
5 |
Correct |
678 ms |
400 KB |
Output is correct |
6 |
Correct |
529 ms |
528 KB |
Output is correct |
7 |
Correct |
548 ms |
528 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
622 ms |
488 KB |
Output is correct |
12 |
Correct |
483 ms |
652 KB |
Output is correct |
13 |
Correct |
478 ms |
684 KB |
Output is correct |
14 |
Correct |
468 ms |
468 KB |
Output is correct |
15 |
Correct |
63 ms |
428 KB |
Output is correct |
16 |
Correct |
81 ms |
528 KB |
Output is correct |
17 |
Correct |
132 ms |
528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1069 ms |
400 KB |
Output is correct |
2 |
Correct |
737 ms |
488 KB |
Output is correct |
3 |
Correct |
665 ms |
400 KB |
Output is correct |
4 |
Correct |
4 ms |
464 KB |
Output is correct |
5 |
Correct |
5 ms |
480 KB |
Output is correct |
6 |
Correct |
2 ms |
464 KB |
Output is correct |
7 |
Correct |
589 ms |
400 KB |
Output is correct |
8 |
Correct |
978 ms |
400 KB |
Output is correct |
9 |
Correct |
671 ms |
400 KB |
Output is correct |
10 |
Correct |
702 ms |
400 KB |
Output is correct |
11 |
Correct |
6 ms |
468 KB |
Output is correct |
12 |
Correct |
7 ms |
464 KB |
Output is correct |
13 |
Correct |
4 ms |
476 KB |
Output is correct |
14 |
Correct |
5 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
519 ms |
528 KB |
Output is correct |
17 |
Correct |
592 ms |
520 KB |
Output is correct |
18 |
Correct |
671 ms |
492 KB |
Output is correct |
19 |
Correct |
536 ms |
400 KB |
Output is correct |
20 |
Correct |
546 ms |
400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
610 ms |
744 KB |
Output is correct |
2 |
Correct |
553 ms |
660 KB |
Output is correct |
3 |
Correct |
1097 ms |
476 KB |
Output is correct |
4 |
Correct |
782 ms |
480 KB |
Output is correct |
5 |
Correct |
741 ms |
400 KB |
Output is correct |
6 |
Correct |
569 ms |
672 KB |
Output is correct |
7 |
Correct |
494 ms |
544 KB |
Output is correct |
8 |
Correct |
3 ms |
476 KB |
Output is correct |
9 |
Correct |
5 ms |
476 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
498 ms |
520 KB |
Output is correct |
12 |
Correct |
637 ms |
528 KB |
Output is correct |
13 |
Correct |
952 ms |
400 KB |
Output is correct |
14 |
Correct |
681 ms |
492 KB |
Output is correct |
15 |
Correct |
669 ms |
400 KB |
Output is correct |
16 |
Correct |
421 ms |
496 KB |
Output is correct |
17 |
Correct |
683 ms |
400 KB |
Output is correct |
18 |
Correct |
464 ms |
648 KB |
Output is correct |
19 |
Correct |
580 ms |
680 KB |
Output is correct |
20 |
Correct |
508 ms |
484 KB |
Output is correct |
21 |
Correct |
66 ms |
420 KB |
Output is correct |
22 |
Correct |
81 ms |
528 KB |
Output is correct |
23 |
Correct |
107 ms |
552 KB |
Output is correct |
24 |
Correct |
5 ms |
468 KB |
Output is correct |
25 |
Correct |
5 ms |
468 KB |
Output is correct |
26 |
Correct |
7 ms |
468 KB |
Output is correct |
27 |
Correct |
4 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
556 ms |
484 KB |
Output is correct |
30 |
Correct |
463 ms |
400 KB |
Output is correct |
31 |
Correct |
577 ms |
528 KB |
Output is correct |
32 |
Correct |
567 ms |
528 KB |
Output is correct |
33 |
Correct |
530 ms |
400 KB |
Output is correct |
34 |
Correct |
392 ms |
656 KB |
Output is correct |
35 |
Correct |
470 ms |
696 KB |
Output is correct |
36 |
Correct |
514 ms |
696 KB |
Output is correct |
37 |
Correct |
575 ms |
604 KB |
Output is correct |
38 |
Correct |
543 ms |
648 KB |
Output is correct |
39 |
Correct |
563 ms |
612 KB |
Output is correct |
40 |
Correct |
531 ms |
612 KB |
Output is correct |
41 |
Correct |
576 ms |
720 KB |
Output is correct |
42 |
Correct |
66 ms |
528 KB |
Output is correct |
43 |
Correct |
137 ms |
548 KB |
Output is correct |
44 |
Correct |
134 ms |
528 KB |
Output is correct |
45 |
Correct |
177 ms |
592 KB |
Output is correct |
46 |
Correct |
305 ms |
488 KB |
Output is correct |
47 |
Correct |
324 ms |
528 KB |
Output is correct |
48 |
Correct |
74 ms |
648 KB |
Output is correct |
49 |
Correct |
70 ms |
640 KB |
Output is correct |