#include<bits/stdc++.h>
#include "stations.h"
using namespace std;
vector<int> path[1001], ret;
bool visited[1001];
int tsize[1001];
int dfs(int x){
int s = 1;
for(int i = 0;i < path[x].size();i++){
if(visited[path[x][i]]) continue;
visited[path[x][i]] = true;
s += dfs(path[x][i]);
}
return tsize[x] = s;
}
void dfs2(int x, int s, int e, int d){
if(d%2 == 0) {ret[x] = s; s++;}
else ret[x] = e;
for(int i = 0;i < path[x].size();i++){
if(visited[path[x][i]]) continue;
visited[path[x][i]] = true;
dfs2(path[x][i], s, s+tsize[path[x][i]]-1, d+1);
s+=tsize[path[x][i]];
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v){
ret.clear();
for(int i = 0;i < n;i++) path[i].clear();
ret.resize(n);
for(int i = 0;i < n-1;i++){
path[u[i]].push_back(v[i]);
path[v[i]].push_back(u[i]);
}
for(int i = 0;i < n;i++) visited[i] = false;
visited[0] = true;
dfs(0);
for(int i = 0;i < n;i++) visited[i] = false;
visited[0] = true;
dfs2(0, 0, n-1, 0);
return ret;
}
int find_next_station(int s, int t, vector<int> c){
if(c[0] < s){
if(t > s || t < c[0]) return c[0];
return c[(int)(upper_bound(c.begin(), c.end(), t) - c.begin()) - 1];
}
else{
if(t < s || t > c.back()) return c.back();
return c[(int)(lower_bound(c.begin(), c.end(), t) - c.begin())];
}
}
Compilation message
stations.cpp: In function 'int dfs(int)':
stations.cpp:10:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | for(int i = 0;i < path[x].size();i++){
| ~~^~~~~~~~~~~~~~~~
stations.cpp: In function 'void dfs2(int, int, int, int)':
stations.cpp:20:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for(int i = 0;i < path[x].size();i++){
| ~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
553 ms |
1008 KB |
Output is correct |
2 |
Correct |
487 ms |
1024 KB |
Output is correct |
3 |
Correct |
858 ms |
768 KB |
Output is correct |
4 |
Correct |
664 ms |
872 KB |
Output is correct |
5 |
Correct |
584 ms |
1048 KB |
Output is correct |
6 |
Correct |
437 ms |
768 KB |
Output is correct |
7 |
Correct |
449 ms |
920 KB |
Output is correct |
8 |
Correct |
3 ms |
768 KB |
Output is correct |
9 |
Correct |
3 ms |
768 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
439 ms |
808 KB |
Output is correct |
2 |
Correct |
529 ms |
820 KB |
Output is correct |
3 |
Correct |
883 ms |
876 KB |
Output is correct |
4 |
Correct |
659 ms |
1028 KB |
Output is correct |
5 |
Correct |
633 ms |
872 KB |
Output is correct |
6 |
Correct |
445 ms |
824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
546 ms |
1148 KB |
Output is correct |
2 |
Correct |
472 ms |
1272 KB |
Output is correct |
3 |
Correct |
892 ms |
872 KB |
Output is correct |
4 |
Correct |
742 ms |
768 KB |
Output is correct |
5 |
Correct |
640 ms |
1000 KB |
Output is correct |
6 |
Correct |
469 ms |
768 KB |
Output is correct |
7 |
Correct |
435 ms |
788 KB |
Output is correct |
8 |
Correct |
3 ms |
872 KB |
Output is correct |
9 |
Correct |
5 ms |
880 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
11 |
Correct |
736 ms |
872 KB |
Output is correct |
12 |
Correct |
590 ms |
776 KB |
Output is correct |
13 |
Correct |
498 ms |
784 KB |
Output is correct |
14 |
Correct |
579 ms |
820 KB |
Output is correct |
15 |
Correct |
59 ms |
860 KB |
Output is correct |
16 |
Correct |
65 ms |
972 KB |
Output is correct |
17 |
Correct |
117 ms |
1160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
891 ms |
1040 KB |
Output is correct |
2 |
Correct |
692 ms |
864 KB |
Output is correct |
3 |
Correct |
752 ms |
872 KB |
Output is correct |
4 |
Correct |
3 ms |
768 KB |
Output is correct |
5 |
Correct |
5 ms |
768 KB |
Output is correct |
6 |
Correct |
1 ms |
896 KB |
Output is correct |
7 |
Correct |
624 ms |
784 KB |
Output is correct |
8 |
Correct |
1057 ms |
872 KB |
Output is correct |
9 |
Correct |
682 ms |
768 KB |
Output is correct |
10 |
Correct |
599 ms |
880 KB |
Output is correct |
11 |
Correct |
6 ms |
1024 KB |
Output is correct |
12 |
Correct |
6 ms |
876 KB |
Output is correct |
13 |
Correct |
6 ms |
876 KB |
Output is correct |
14 |
Correct |
5 ms |
884 KB |
Output is correct |
15 |
Correct |
1 ms |
768 KB |
Output is correct |
16 |
Correct |
488 ms |
768 KB |
Output is correct |
17 |
Correct |
618 ms |
768 KB |
Output is correct |
18 |
Correct |
691 ms |
1032 KB |
Output is correct |
19 |
Correct |
674 ms |
872 KB |
Output is correct |
20 |
Correct |
482 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
546 ms |
772 KB |
Output is correct |
2 |
Correct |
513 ms |
776 KB |
Output is correct |
3 |
Correct |
904 ms |
896 KB |
Output is correct |
4 |
Correct |
661 ms |
1040 KB |
Output is correct |
5 |
Correct |
647 ms |
880 KB |
Output is correct |
6 |
Correct |
516 ms |
768 KB |
Output is correct |
7 |
Correct |
434 ms |
800 KB |
Output is correct |
8 |
Correct |
3 ms |
1004 KB |
Output is correct |
9 |
Correct |
5 ms |
872 KB |
Output is correct |
10 |
Correct |
2 ms |
768 KB |
Output is correct |
11 |
Correct |
553 ms |
808 KB |
Output is correct |
12 |
Correct |
622 ms |
820 KB |
Output is correct |
13 |
Correct |
1000 ms |
768 KB |
Output is correct |
14 |
Correct |
736 ms |
1000 KB |
Output is correct |
15 |
Correct |
738 ms |
900 KB |
Output is correct |
16 |
Correct |
570 ms |
768 KB |
Output is correct |
17 |
Correct |
640 ms |
872 KB |
Output is correct |
18 |
Correct |
486 ms |
888 KB |
Output is correct |
19 |
Correct |
468 ms |
768 KB |
Output is correct |
20 |
Correct |
447 ms |
824 KB |
Output is correct |
21 |
Correct |
62 ms |
768 KB |
Output is correct |
22 |
Correct |
76 ms |
960 KB |
Output is correct |
23 |
Correct |
105 ms |
1024 KB |
Output is correct |
24 |
Correct |
6 ms |
768 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 |
768 KB |
Output is correct |
28 |
Correct |
1 ms |
768 KB |
Output is correct |
29 |
Correct |
497 ms |
768 KB |
Output is correct |
30 |
Correct |
606 ms |
872 KB |
Output is correct |
31 |
Correct |
511 ms |
884 KB |
Output is correct |
32 |
Correct |
481 ms |
1040 KB |
Output is correct |
33 |
Correct |
523 ms |
768 KB |
Output is correct |
34 |
Correct |
313 ms |
1024 KB |
Output is correct |
35 |
Correct |
566 ms |
1008 KB |
Output is correct |
36 |
Correct |
474 ms |
768 KB |
Output is correct |
37 |
Correct |
466 ms |
888 KB |
Output is correct |
38 |
Correct |
567 ms |
992 KB |
Output is correct |
39 |
Correct |
493 ms |
784 KB |
Output is correct |
40 |
Correct |
492 ms |
896 KB |
Output is correct |
41 |
Correct |
520 ms |
784 KB |
Output is correct |
42 |
Correct |
64 ms |
768 KB |
Output is correct |
43 |
Correct |
107 ms |
824 KB |
Output is correct |
44 |
Correct |
137 ms |
1024 KB |
Output is correct |
45 |
Correct |
224 ms |
768 KB |
Output is correct |
46 |
Correct |
415 ms |
824 KB |
Output is correct |
47 |
Correct |
352 ms |
804 KB |
Output is correct |
48 |
Correct |
75 ms |
768 KB |
Output is correct |
49 |
Correct |
79 ms |
1024 KB |
Output is correct |