#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<int> labels(n);
vector<vector<int>> adj(n);
for (int i = 0; i + 1 < n; i++) {
adj[u[i]].emplace_back(v[i]);
adj[v[i]].emplace_back(u[i]);
}
vector<int> st(n), et(n);
int timer = 0;
const function<void(int, int, int)> Dfs = [&](int u, int p, int odd) {
st[u] = timer++;
for (auto v : adj[u]) if (v != p) {
Dfs(v, u, odd ^ 1);
}
et[u] = timer++;
if (odd) {
labels[u] = st[u];
} else {
labels[u] = et[u];
}
};
Dfs(0, -1, 0);
vector<int> coords = labels;
sort(begin(coords), end(coords));
for (int i = 0; i < n; i++) {
labels[i] = lower_bound(begin(coords), end(coords), labels[i]) - begin(coords);
}
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
if (s < *min_element(begin(c), end(c))) {
int par = c.back();
for (auto u : c) {
if (u != par && s <= t && t <= u) {
return u;
}
}
return par;
} else {
reverse(begin(c), end(c));
int par = c.back();
for (auto u : c) {
if (u != par && u <= t && t <= s) {
return u;
}
}
return par;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
582 ms |
1008 KB |
Output is correct |
2 |
Correct |
496 ms |
1280 KB |
Output is correct |
3 |
Correct |
969 ms |
640 KB |
Output is correct |
4 |
Correct |
764 ms |
648 KB |
Output is correct |
5 |
Correct |
590 ms |
640 KB |
Output is correct |
6 |
Correct |
544 ms |
1024 KB |
Output is correct |
7 |
Correct |
537 ms |
1024 KB |
Output is correct |
8 |
Correct |
2 ms |
660 KB |
Output is correct |
9 |
Correct |
4 ms |
640 KB |
Output is correct |
10 |
Correct |
2 ms |
656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
469 ms |
820 KB |
Output is correct |
2 |
Correct |
567 ms |
808 KB |
Output is correct |
3 |
Correct |
872 ms |
772 KB |
Output is correct |
4 |
Correct |
690 ms |
640 KB |
Output is correct |
5 |
Correct |
618 ms |
656 KB |
Output is correct |
6 |
Correct |
511 ms |
948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
589 ms |
1024 KB |
Output is correct |
2 |
Correct |
503 ms |
1008 KB |
Output is correct |
3 |
Correct |
1065 ms |
640 KB |
Output is correct |
4 |
Correct |
696 ms |
640 KB |
Output is correct |
5 |
Correct |
808 ms |
784 KB |
Output is correct |
6 |
Correct |
559 ms |
1024 KB |
Output is correct |
7 |
Correct |
487 ms |
1024 KB |
Output is correct |
8 |
Correct |
3 ms |
648 KB |
Output is correct |
9 |
Correct |
4 ms |
640 KB |
Output is correct |
10 |
Correct |
2 ms |
640 KB |
Output is correct |
11 |
Correct |
692 ms |
640 KB |
Output is correct |
12 |
Correct |
588 ms |
1084 KB |
Output is correct |
13 |
Correct |
572 ms |
1092 KB |
Output is correct |
14 |
Correct |
508 ms |
772 KB |
Output is correct |
15 |
Correct |
61 ms |
1024 KB |
Output is correct |
16 |
Correct |
69 ms |
856 KB |
Output is correct |
17 |
Correct |
116 ms |
804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
909 ms |
776 KB |
Output is correct |
2 |
Correct |
667 ms |
644 KB |
Output is correct |
3 |
Correct |
594 ms |
784 KB |
Output is correct |
4 |
Correct |
3 ms |
640 KB |
Output is correct |
5 |
Correct |
5 ms |
640 KB |
Output is correct |
6 |
Correct |
2 ms |
640 KB |
Output is correct |
7 |
Correct |
641 ms |
784 KB |
Output is correct |
8 |
Correct |
879 ms |
648 KB |
Output is correct |
9 |
Correct |
711 ms |
640 KB |
Output is correct |
10 |
Correct |
602 ms |
672 KB |
Output is correct |
11 |
Correct |
5 ms |
640 KB |
Output is correct |
12 |
Correct |
6 ms |
776 KB |
Output is correct |
13 |
Correct |
4 ms |
640 KB |
Output is correct |
14 |
Correct |
3 ms |
640 KB |
Output is correct |
15 |
Correct |
2 ms |
644 KB |
Output is correct |
16 |
Correct |
506 ms |
640 KB |
Output is correct |
17 |
Correct |
499 ms |
644 KB |
Output is correct |
18 |
Correct |
494 ms |
756 KB |
Output is correct |
19 |
Correct |
487 ms |
640 KB |
Output is correct |
20 |
Correct |
529 ms |
644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
550 ms |
1024 KB |
Output is correct |
2 |
Correct |
462 ms |
1008 KB |
Output is correct |
3 |
Correct |
908 ms |
776 KB |
Output is correct |
4 |
Correct |
677 ms |
640 KB |
Output is correct |
5 |
Correct |
586 ms |
640 KB |
Output is correct |
6 |
Correct |
445 ms |
1448 KB |
Output is correct |
7 |
Correct |
476 ms |
1024 KB |
Output is correct |
8 |
Correct |
2 ms |
644 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
2 ms |
644 KB |
Output is correct |
11 |
Correct |
455 ms |
820 KB |
Output is correct |
12 |
Correct |
531 ms |
804 KB |
Output is correct |
13 |
Correct |
867 ms |
640 KB |
Output is correct |
14 |
Correct |
651 ms |
640 KB |
Output is correct |
15 |
Correct |
635 ms |
640 KB |
Output is correct |
16 |
Correct |
455 ms |
816 KB |
Output is correct |
17 |
Correct |
589 ms |
640 KB |
Output is correct |
18 |
Correct |
464 ms |
1116 KB |
Output is correct |
19 |
Correct |
499 ms |
1024 KB |
Output is correct |
20 |
Correct |
478 ms |
816 KB |
Output is correct |
21 |
Correct |
57 ms |
900 KB |
Output is correct |
22 |
Correct |
74 ms |
860 KB |
Output is correct |
23 |
Correct |
111 ms |
780 KB |
Output is correct |
24 |
Correct |
5 ms |
892 KB |
Output is correct |
25 |
Correct |
6 ms |
644 KB |
Output is correct |
26 |
Correct |
5 ms |
640 KB |
Output is correct |
27 |
Correct |
4 ms |
640 KB |
Output is correct |
28 |
Correct |
2 ms |
784 KB |
Output is correct |
29 |
Correct |
518 ms |
1028 KB |
Output is correct |
30 |
Correct |
508 ms |
772 KB |
Output is correct |
31 |
Correct |
498 ms |
648 KB |
Output is correct |
32 |
Correct |
549 ms |
644 KB |
Output is correct |
33 |
Correct |
508 ms |
640 KB |
Output is correct |
34 |
Correct |
326 ms |
1024 KB |
Output is correct |
35 |
Correct |
437 ms |
1024 KB |
Output is correct |
36 |
Correct |
479 ms |
1104 KB |
Output is correct |
37 |
Correct |
499 ms |
916 KB |
Output is correct |
38 |
Correct |
473 ms |
796 KB |
Output is correct |
39 |
Correct |
471 ms |
896 KB |
Output is correct |
40 |
Correct |
457 ms |
772 KB |
Output is correct |
41 |
Correct |
469 ms |
780 KB |
Output is correct |
42 |
Correct |
65 ms |
960 KB |
Output is correct |
43 |
Correct |
106 ms |
768 KB |
Output is correct |
44 |
Correct |
149 ms |
768 KB |
Output is correct |
45 |
Correct |
153 ms |
804 KB |
Output is correct |
46 |
Correct |
329 ms |
768 KB |
Output is correct |
47 |
Correct |
311 ms |
1024 KB |
Output is correct |
48 |
Correct |
64 ms |
768 KB |
Output is correct |
49 |
Correct |
65 ms |
804 KB |
Output is correct |