#include <bits/stdc++.h>
#include "stations.h"
using namespace std;
vector<int> label(int N, int K, vector<int> u, vector<int> v)
{
vector<vector<int>> con(N);
for (int i=0;i<N-1;i++)
con[u[i]].push_back(v[i]),
con[v[i]].push_back(u[i]);
vector<int> labels(N); int idx = 0;
function<void(int, int)> dfs;
dfs = [&](int n, int p){
if (p == -1 || !labels[p]) labels[n] = ++idx;
for (int t: con[n]) if (t != p)
dfs(t, n);
if (!labels[n]) labels[n] = ++idx;
};
dfs(0, -1);
return labels;
}
int find_next_station(int s, int t, vector<int> c)
{
if (c.back() < s) reverse(c.begin(), c.end());
for (int x: c) if (min(s, x) <= t && t <= max(s, x)) return x;
return c.back();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
577 ms |
1024 KB |
Output is correct |
2 |
Correct |
469 ms |
1024 KB |
Output is correct |
3 |
Correct |
986 ms |
648 KB |
Output is correct |
4 |
Correct |
670 ms |
644 KB |
Output is correct |
5 |
Correct |
621 ms |
640 KB |
Output is correct |
6 |
Correct |
472 ms |
1024 KB |
Output is correct |
7 |
Correct |
465 ms |
772 KB |
Output is correct |
8 |
Correct |
3 ms |
648 KB |
Output is correct |
9 |
Correct |
5 ms |
644 KB |
Output is correct |
10 |
Correct |
2 ms |
644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
481 ms |
768 KB |
Output is correct |
2 |
Correct |
536 ms |
936 KB |
Output is correct |
3 |
Correct |
856 ms |
640 KB |
Output is correct |
4 |
Correct |
682 ms |
640 KB |
Output is correct |
5 |
Correct |
544 ms |
648 KB |
Output is correct |
6 |
Correct |
436 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
543 ms |
1024 KB |
Output is correct |
2 |
Correct |
496 ms |
1000 KB |
Output is correct |
3 |
Correct |
895 ms |
640 KB |
Output is correct |
4 |
Correct |
713 ms |
640 KB |
Output is correct |
5 |
Correct |
689 ms |
756 KB |
Output is correct |
6 |
Correct |
514 ms |
1024 KB |
Output is correct |
7 |
Correct |
479 ms |
780 KB |
Output is correct |
8 |
Correct |
3 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
648 KB |
Output is correct |
10 |
Correct |
2 ms |
896 KB |
Output is correct |
11 |
Correct |
689 ms |
908 KB |
Output is correct |
12 |
Correct |
464 ms |
1024 KB |
Output is correct |
13 |
Correct |
564 ms |
1024 KB |
Output is correct |
14 |
Correct |
546 ms |
816 KB |
Output is correct |
15 |
Correct |
54 ms |
648 KB |
Output is correct |
16 |
Correct |
67 ms |
768 KB |
Output is correct |
17 |
Correct |
130 ms |
960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1005 ms |
640 KB |
Output is correct |
2 |
Correct |
798 ms |
644 KB |
Output is correct |
3 |
Correct |
584 ms |
648 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 |
633 ms |
768 KB |
Output is correct |
8 |
Correct |
874 ms |
644 KB |
Output is correct |
9 |
Correct |
686 ms |
648 KB |
Output is correct |
10 |
Correct |
598 ms |
776 KB |
Output is correct |
11 |
Correct |
5 ms |
640 KB |
Output is correct |
12 |
Correct |
6 ms |
640 KB |
Output is correct |
13 |
Correct |
5 ms |
640 KB |
Output is correct |
14 |
Correct |
4 ms |
644 KB |
Output is correct |
15 |
Correct |
2 ms |
648 KB |
Output is correct |
16 |
Correct |
529 ms |
768 KB |
Output is correct |
17 |
Correct |
504 ms |
640 KB |
Output is correct |
18 |
Correct |
519 ms |
640 KB |
Output is correct |
19 |
Correct |
508 ms |
640 KB |
Output is correct |
20 |
Correct |
498 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
515 ms |
1024 KB |
Output is correct |
2 |
Correct |
433 ms |
1024 KB |
Output is correct |
3 |
Correct |
934 ms |
648 KB |
Output is correct |
4 |
Correct |
704 ms |
640 KB |
Output is correct |
5 |
Correct |
571 ms |
644 KB |
Output is correct |
6 |
Correct |
475 ms |
1024 KB |
Output is correct |
7 |
Correct |
479 ms |
768 KB |
Output is correct |
8 |
Correct |
3 ms |
644 KB |
Output is correct |
9 |
Correct |
4 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
640 KB |
Output is correct |
11 |
Correct |
536 ms |
768 KB |
Output is correct |
12 |
Correct |
610 ms |
820 KB |
Output is correct |
13 |
Correct |
922 ms |
768 KB |
Output is correct |
14 |
Correct |
671 ms |
640 KB |
Output is correct |
15 |
Correct |
589 ms |
640 KB |
Output is correct |
16 |
Correct |
466 ms |
828 KB |
Output is correct |
17 |
Correct |
590 ms |
640 KB |
Output is correct |
18 |
Correct |
473 ms |
888 KB |
Output is correct |
19 |
Correct |
485 ms |
1132 KB |
Output is correct |
20 |
Correct |
532 ms |
824 KB |
Output is correct |
21 |
Correct |
51 ms |
788 KB |
Output is correct |
22 |
Correct |
89 ms |
856 KB |
Output is correct |
23 |
Correct |
111 ms |
768 KB |
Output is correct |
24 |
Correct |
7 ms |
640 KB |
Output is correct |
25 |
Correct |
6 ms |
640 KB |
Output is correct |
26 |
Correct |
5 ms |
648 KB |
Output is correct |
27 |
Correct |
4 ms |
640 KB |
Output is correct |
28 |
Correct |
2 ms |
640 KB |
Output is correct |
29 |
Correct |
511 ms |
640 KB |
Output is correct |
30 |
Correct |
578 ms |
648 KB |
Output is correct |
31 |
Correct |
531 ms |
640 KB |
Output is correct |
32 |
Correct |
607 ms |
772 KB |
Output is correct |
33 |
Correct |
609 ms |
652 KB |
Output is correct |
34 |
Correct |
360 ms |
768 KB |
Output is correct |
35 |
Correct |
487 ms |
1024 KB |
Output is correct |
36 |
Correct |
495 ms |
880 KB |
Output is correct |
37 |
Correct |
511 ms |
888 KB |
Output is correct |
38 |
Correct |
564 ms |
792 KB |
Output is correct |
39 |
Correct |
454 ms |
792 KB |
Output is correct |
40 |
Correct |
441 ms |
1152 KB |
Output is correct |
41 |
Correct |
450 ms |
804 KB |
Output is correct |
42 |
Correct |
65 ms |
896 KB |
Output is correct |
43 |
Correct |
103 ms |
820 KB |
Output is correct |
44 |
Correct |
135 ms |
836 KB |
Output is correct |
45 |
Correct |
176 ms |
884 KB |
Output is correct |
46 |
Correct |
318 ms |
828 KB |
Output is correct |
47 |
Correct |
339 ms |
792 KB |
Output is correct |
48 |
Correct |
68 ms |
820 KB |
Output is correct |
49 |
Correct |
60 ms |
820 KB |
Output is correct |