#include "stations.h"
#include <vector>
#include <algorithm>
std::vector<int> graph[1000];
bool even[1000];
int tin[1000], tout[1000], timer;
void dfs(int node = 0, int parent = -1, bool even = true) {
tin[node] = timer++;
::even[node] = even;
for (int i : graph[node]) if (i != parent) dfs(i, node, !even);
tout[node] = timer++;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
for (int i = 0; i < n; i++) graph[i].clear();
for (int i = 0; i < n - 1; i++) {
graph[u[i]].push_back(v[i]);
graph[v[i]].push_back(u[i]);
}
timer = 0;
dfs();
std::vector<int> labels(n);
for (int i = 0; i < n; i++) labels[i] = (even[i] ? tin[i] : tout[i]) / 2;
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
int mx = *std::max_element(c.begin(), c.end());
int mn = *std::min_element(c.begin(), c.end());
if (s < mn) {
if (t < s || t > mx) return mx;
return *std::lower_bound(c.begin(), c.end(), t);
} else {
if (t > s || t < mn) return mn;
return *prev(std::upper_bound(c.begin(), c.end(), t));
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
525 ms |
992 KB |
Output is correct |
2 |
Correct |
462 ms |
864 KB |
Output is correct |
3 |
Correct |
889 ms |
848 KB |
Output is correct |
4 |
Correct |
670 ms |
856 KB |
Output is correct |
5 |
Correct |
567 ms |
976 KB |
Output is correct |
6 |
Correct |
447 ms |
1004 KB |
Output is correct |
7 |
Correct |
529 ms |
760 KB |
Output is correct |
8 |
Correct |
2 ms |
856 KB |
Output is correct |
9 |
Correct |
4 ms |
884 KB |
Output is correct |
10 |
Correct |
1 ms |
756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
469 ms |
796 KB |
Output is correct |
2 |
Correct |
565 ms |
804 KB |
Output is correct |
3 |
Correct |
881 ms |
848 KB |
Output is correct |
4 |
Correct |
714 ms |
856 KB |
Output is correct |
5 |
Correct |
686 ms |
736 KB |
Output is correct |
6 |
Correct |
453 ms |
756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
499 ms |
884 KB |
Output is correct |
2 |
Correct |
433 ms |
988 KB |
Output is correct |
3 |
Correct |
873 ms |
788 KB |
Output is correct |
4 |
Correct |
780 ms |
736 KB |
Output is correct |
5 |
Correct |
581 ms |
976 KB |
Output is correct |
6 |
Correct |
501 ms |
1184 KB |
Output is correct |
7 |
Correct |
480 ms |
756 KB |
Output is correct |
8 |
Correct |
3 ms |
776 KB |
Output is correct |
9 |
Correct |
4 ms |
884 KB |
Output is correct |
10 |
Correct |
1 ms |
736 KB |
Output is correct |
11 |
Correct |
579 ms |
984 KB |
Output is correct |
12 |
Correct |
558 ms |
1224 KB |
Output is correct |
13 |
Correct |
491 ms |
1232 KB |
Output is correct |
14 |
Correct |
495 ms |
756 KB |
Output is correct |
15 |
Correct |
55 ms |
796 KB |
Output is correct |
16 |
Correct |
65 ms |
864 KB |
Output is correct |
17 |
Correct |
109 ms |
892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
864 ms |
896 KB |
Output is correct |
2 |
Correct |
662 ms |
736 KB |
Output is correct |
3 |
Correct |
638 ms |
848 KB |
Output is correct |
4 |
Correct |
3 ms |
756 KB |
Output is correct |
5 |
Correct |
4 ms |
776 KB |
Output is correct |
6 |
Correct |
1 ms |
756 KB |
Output is correct |
7 |
Correct |
600 ms |
864 KB |
Output is correct |
8 |
Correct |
928 ms |
864 KB |
Output is correct |
9 |
Correct |
707 ms |
756 KB |
Output is correct |
10 |
Correct |
698 ms |
848 KB |
Output is correct |
11 |
Correct |
6 ms |
848 KB |
Output is correct |
12 |
Correct |
7 ms |
736 KB |
Output is correct |
13 |
Correct |
5 ms |
796 KB |
Output is correct |
14 |
Correct |
5 ms |
756 KB |
Output is correct |
15 |
Correct |
2 ms |
736 KB |
Output is correct |
16 |
Correct |
575 ms |
896 KB |
Output is correct |
17 |
Correct |
525 ms |
756 KB |
Output is correct |
18 |
Correct |
520 ms |
848 KB |
Output is correct |
19 |
Correct |
511 ms |
976 KB |
Output is correct |
20 |
Correct |
515 ms |
1008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
535 ms |
1132 KB |
Output is correct |
2 |
Correct |
431 ms |
992 KB |
Output is correct |
3 |
Correct |
856 ms |
848 KB |
Output is correct |
4 |
Correct |
832 ms |
976 KB |
Output is correct |
5 |
Correct |
658 ms |
848 KB |
Output is correct |
6 |
Correct |
467 ms |
992 KB |
Output is correct |
7 |
Correct |
505 ms |
756 KB |
Output is correct |
8 |
Correct |
3 ms |
756 KB |
Output is correct |
9 |
Correct |
5 ms |
736 KB |
Output is correct |
10 |
Correct |
1 ms |
884 KB |
Output is correct |
11 |
Correct |
499 ms |
756 KB |
Output is correct |
12 |
Correct |
628 ms |
756 KB |
Output is correct |
13 |
Correct |
885 ms |
756 KB |
Output is correct |
14 |
Correct |
560 ms |
788 KB |
Output is correct |
15 |
Correct |
805 ms |
756 KB |
Output is correct |
16 |
Correct |
459 ms |
736 KB |
Output is correct |
17 |
Correct |
602 ms |
736 KB |
Output is correct |
18 |
Correct |
470 ms |
868 KB |
Output is correct |
19 |
Correct |
457 ms |
908 KB |
Output is correct |
20 |
Correct |
451 ms |
736 KB |
Output is correct |
21 |
Correct |
59 ms |
848 KB |
Output is correct |
22 |
Correct |
66 ms |
864 KB |
Output is correct |
23 |
Correct |
101 ms |
864 KB |
Output is correct |
24 |
Correct |
5 ms |
840 KB |
Output is correct |
25 |
Correct |
6 ms |
848 KB |
Output is correct |
26 |
Correct |
4 ms |
736 KB |
Output is correct |
27 |
Correct |
3 ms |
736 KB |
Output is correct |
28 |
Correct |
1 ms |
896 KB |
Output is correct |
29 |
Correct |
506 ms |
884 KB |
Output is correct |
30 |
Correct |
512 ms |
756 KB |
Output is correct |
31 |
Correct |
516 ms |
848 KB |
Output is correct |
32 |
Correct |
509 ms |
756 KB |
Output is correct |
33 |
Correct |
503 ms |
848 KB |
Output is correct |
34 |
Correct |
311 ms |
1004 KB |
Output is correct |
35 |
Correct |
429 ms |
1216 KB |
Output is correct |
36 |
Correct |
475 ms |
1100 KB |
Output is correct |
37 |
Correct |
500 ms |
864 KB |
Output is correct |
38 |
Correct |
506 ms |
992 KB |
Output is correct |
39 |
Correct |
497 ms |
1112 KB |
Output is correct |
40 |
Correct |
423 ms |
1120 KB |
Output is correct |
41 |
Correct |
455 ms |
996 KB |
Output is correct |
42 |
Correct |
62 ms |
864 KB |
Output is correct |
43 |
Correct |
102 ms |
900 KB |
Output is correct |
44 |
Correct |
121 ms |
904 KB |
Output is correct |
45 |
Correct |
153 ms |
736 KB |
Output is correct |
46 |
Correct |
290 ms |
796 KB |
Output is correct |
47 |
Correct |
311 ms |
776 KB |
Output is correct |
48 |
Correct |
65 ms |
1104 KB |
Output is correct |
49 |
Correct |
60 ms |
1108 KB |
Output is correct |