#include <bits/stdc++.h>
#include "stations.h"
using namespace std;
const int c=1002;
vector<int> sz[c], sol;
bool v[c];
int cnt;
void dfs(int a, bool b) {
v[a]=1;
if (!b) sol[a]=cnt++;
for (int i=0; i<sz[a].size(); i++) {
int x=sz[a][i];
if (!v[x]) dfs(x, !b);
}
if (b) sol[a]=cnt++;
}
vector<int> label(int n, int k, vector<int> x, vector<int> y) {
for (int i=0; i<n; i++) sz[i].clear(), v[i]=0, cnt=0, sol.clear();
sol.resize(n);
for (int i=0; i<n-1; i++) sz[x[i]].push_back(y[i]), sz[y[i]].push_back(x[i]);
dfs(0, 0);
return sol;
}
int find_next_station(int s, int t, vector<int> sz) {
int x=sz[0], y=sz.back(), si=sz.size();
if (s<x) {
if (t<s || t>y) return y;
for (int i=0; i<si; i++) if (sz[i]>=t) return sz[i];
}
if (t>s || t<x) return x;
for (int i=si-1; i>0; i--) if (sz[i]<=t) return sz[i];
}
Compilation message
stations.cpp: In function 'void dfs(int, bool)':
stations.cpp:11:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | for (int i=0; i<sz[a].size(); i++) {
| ~^~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:32:1: warning: control reaches end of non-void function [-Wreturn-type]
32 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
554 ms |
1024 KB |
Output is correct |
2 |
Correct |
586 ms |
768 KB |
Output is correct |
3 |
Correct |
1154 ms |
872 KB |
Output is correct |
4 |
Correct |
745 ms |
672 KB |
Output is correct |
5 |
Correct |
713 ms |
856 KB |
Output is correct |
6 |
Correct |
558 ms |
768 KB |
Output is correct |
7 |
Correct |
564 ms |
768 KB |
Output is correct |
8 |
Correct |
3 ms |
768 KB |
Output is correct |
9 |
Correct |
5 ms |
768 KB |
Output is correct |
10 |
Correct |
2 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
488 ms |
812 KB |
Output is correct |
2 |
Correct |
530 ms |
824 KB |
Output is correct |
3 |
Correct |
1061 ms |
768 KB |
Output is correct |
4 |
Correct |
682 ms |
768 KB |
Output is correct |
5 |
Correct |
631 ms |
768 KB |
Output is correct |
6 |
Correct |
466 ms |
824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
552 ms |
768 KB |
Output is correct |
2 |
Correct |
448 ms |
776 KB |
Output is correct |
3 |
Correct |
922 ms |
768 KB |
Output is correct |
4 |
Correct |
802 ms |
1068 KB |
Output is correct |
5 |
Correct |
668 ms |
876 KB |
Output is correct |
6 |
Correct |
446 ms |
768 KB |
Output is correct |
7 |
Correct |
494 ms |
768 KB |
Output is correct |
8 |
Correct |
2 ms |
768 KB |
Output is correct |
9 |
Correct |
5 ms |
1024 KB |
Output is correct |
10 |
Correct |
1 ms |
876 KB |
Output is correct |
11 |
Correct |
754 ms |
768 KB |
Output is correct |
12 |
Correct |
544 ms |
772 KB |
Output is correct |
13 |
Correct |
499 ms |
776 KB |
Output is correct |
14 |
Correct |
519 ms |
824 KB |
Output is correct |
15 |
Correct |
51 ms |
864 KB |
Output is correct |
16 |
Correct |
64 ms |
836 KB |
Output is correct |
17 |
Correct |
113 ms |
816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
971 ms |
1008 KB |
Output is correct |
2 |
Correct |
726 ms |
1024 KB |
Output is correct |
3 |
Correct |
647 ms |
884 KB |
Output is correct |
4 |
Correct |
3 ms |
880 KB |
Output is correct |
5 |
Correct |
4 ms |
872 KB |
Output is correct |
6 |
Correct |
1 ms |
876 KB |
Output is correct |
7 |
Correct |
800 ms |
768 KB |
Output is correct |
8 |
Correct |
905 ms |
768 KB |
Output is correct |
9 |
Correct |
660 ms |
876 KB |
Output is correct |
10 |
Correct |
572 ms |
768 KB |
Output is correct |
11 |
Correct |
5 ms |
872 KB |
Output is correct |
12 |
Correct |
6 ms |
1132 KB |
Output is correct |
13 |
Correct |
4 ms |
888 KB |
Output is correct |
14 |
Correct |
4 ms |
1004 KB |
Output is correct |
15 |
Correct |
2 ms |
888 KB |
Output is correct |
16 |
Correct |
479 ms |
880 KB |
Output is correct |
17 |
Correct |
578 ms |
768 KB |
Output is correct |
18 |
Correct |
582 ms |
768 KB |
Output is correct |
19 |
Correct |
572 ms |
768 KB |
Output is correct |
20 |
Correct |
543 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
578 ms |
1232 KB |
Output is correct |
2 |
Correct |
466 ms |
768 KB |
Output is correct |
3 |
Correct |
905 ms |
1024 KB |
Output is correct |
4 |
Correct |
797 ms |
876 KB |
Output is correct |
5 |
Correct |
685 ms |
880 KB |
Output is correct |
6 |
Correct |
435 ms |
776 KB |
Output is correct |
7 |
Correct |
471 ms |
768 KB |
Output is correct |
8 |
Correct |
3 ms |
768 KB |
Output is correct |
9 |
Correct |
4 ms |
876 KB |
Output is correct |
10 |
Correct |
1 ms |
876 KB |
Output is correct |
11 |
Correct |
496 ms |
768 KB |
Output is correct |
12 |
Correct |
520 ms |
768 KB |
Output is correct |
13 |
Correct |
891 ms |
768 KB |
Output is correct |
14 |
Correct |
687 ms |
768 KB |
Output is correct |
15 |
Correct |
574 ms |
768 KB |
Output is correct |
16 |
Correct |
450 ms |
832 KB |
Output is correct |
17 |
Correct |
697 ms |
768 KB |
Output is correct |
18 |
Correct |
478 ms |
912 KB |
Output is correct |
19 |
Correct |
521 ms |
1140 KB |
Output is correct |
20 |
Correct |
435 ms |
832 KB |
Output is correct |
21 |
Correct |
61 ms |
768 KB |
Output is correct |
22 |
Correct |
93 ms |
844 KB |
Output is correct |
23 |
Correct |
100 ms |
808 KB |
Output is correct |
24 |
Correct |
7 ms |
884 KB |
Output is correct |
25 |
Correct |
6 ms |
768 KB |
Output is correct |
26 |
Correct |
5 ms |
880 KB |
Output is correct |
27 |
Correct |
4 ms |
876 KB |
Output is correct |
28 |
Correct |
1 ms |
768 KB |
Output is correct |
29 |
Correct |
519 ms |
880 KB |
Output is correct |
30 |
Correct |
517 ms |
888 KB |
Output is correct |
31 |
Correct |
563 ms |
872 KB |
Output is correct |
32 |
Correct |
475 ms |
1024 KB |
Output is correct |
33 |
Correct |
513 ms |
1012 KB |
Output is correct |
34 |
Correct |
347 ms |
908 KB |
Output is correct |
35 |
Correct |
500 ms |
1008 KB |
Output is correct |
36 |
Correct |
540 ms |
888 KB |
Output is correct |
37 |
Correct |
554 ms |
888 KB |
Output is correct |
38 |
Correct |
494 ms |
780 KB |
Output is correct |
39 |
Correct |
513 ms |
784 KB |
Output is correct |
40 |
Correct |
434 ms |
784 KB |
Output is correct |
41 |
Correct |
510 ms |
908 KB |
Output is correct |
42 |
Correct |
71 ms |
828 KB |
Output is correct |
43 |
Correct |
137 ms |
768 KB |
Output is correct |
44 |
Correct |
160 ms |
796 KB |
Output is correct |
45 |
Correct |
207 ms |
768 KB |
Output is correct |
46 |
Correct |
333 ms |
904 KB |
Output is correct |
47 |
Correct |
398 ms |
796 KB |
Output is correct |
48 |
Correct |
81 ms |
796 KB |
Output is correct |
49 |
Correct |
77 ms |
1024 KB |
Output is correct |