#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
const int N=1005;
vector<vector<int>> a(N);
vector<int> ans(N);
int i,n,k,m,x,j,t;
void DFS(vector<vector<int>> a, int x,int y,int d){
if(d%2==0) {ans[y]=t; t++;}
for(int i=0; i<a[y].size(); i++){
if(a[y][i]==x) continue;
DFS(a,y,a[y][i],d+1);
}
if(d%2!=0) {ans[y]=t; t++;}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<int> label(n);
for(i=0; i<n; i++){
a[i].clear();
ans[i]=0;
}
for(i=0; i<n-1; i++){
a[u[i]].push_back(v[i]);
a[v[i]].push_back(u[i]);
}
t=0;
DFS(a,-1,0,0);
for(i=0; i<n; i++) label[i]=ans[i];
return label;
}
int find_next_station(int s, int t, vector<int> c) {
bool parent=true;
int ans;
if(s<c[0]){
c.insert(c.begin(),s);
for(int i=1; i<c.size()-1; i++){
if(t<=c[i] && t>=c[i-1]+1) return c[i];
}
return c[c.size()-1];
}
else{
c.push_back(s);
for(int i=1; i<c.size()-1; i++){
if(t>=c[i] && t<=c[i+1]-1) return c[i];
}
return c[0];
}
}
Compilation message
stations.cpp: In function 'void DFS(std::vector<std::vector<int> >, int, int, int)':
stations.cpp:11:16: 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<a[y].size(); i++){
| ~^~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:40:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(int i=1; i<c.size()-1; i++){
| ~^~~~~~~~~~~
stations.cpp:47:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int i=1; i<c.size()-1; i++){
| ~^~~~~~~~~~~
stations.cpp:35:7: warning: unused variable 'parent' [-Wunused-variable]
35 | bool parent=true;
| ^~~~~~
stations.cpp:36:6: warning: unused variable 'ans' [-Wunused-variable]
36 | int ans;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
864 ms |
55904 KB |
Output is correct |
2 |
Correct |
1125 ms |
55520 KB |
Output is correct |
3 |
Correct |
894 ms |
864 KB |
Output is correct |
4 |
Correct |
653 ms |
992 KB |
Output is correct |
5 |
Correct |
612 ms |
1088 KB |
Output is correct |
6 |
Correct |
1039 ms |
50012 KB |
Output is correct |
7 |
Correct |
613 ms |
42208 KB |
Output is correct |
8 |
Correct |
3 ms |
864 KB |
Output is correct |
9 |
Correct |
5 ms |
1040 KB |
Output is correct |
10 |
Correct |
2 ms |
992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1005 ms |
1624 KB |
Output is correct |
2 |
Correct |
718 ms |
1412 KB |
Output is correct |
3 |
Correct |
879 ms |
1024 KB |
Output is correct |
4 |
Correct |
698 ms |
1120 KB |
Output is correct |
5 |
Correct |
695 ms |
1108 KB |
Output is correct |
6 |
Correct |
500 ms |
1376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
986 ms |
55904 KB |
Output is correct |
2 |
Correct |
1109 ms |
53992 KB |
Output is correct |
3 |
Correct |
1019 ms |
864 KB |
Output is correct |
4 |
Correct |
739 ms |
1108 KB |
Output is correct |
5 |
Correct |
631 ms |
864 KB |
Output is correct |
6 |
Correct |
1185 ms |
54132 KB |
Output is correct |
7 |
Correct |
606 ms |
43196 KB |
Output is correct |
8 |
Correct |
3 ms |
864 KB |
Output is correct |
9 |
Correct |
5 ms |
992 KB |
Output is correct |
10 |
Correct |
2 ms |
992 KB |
Output is correct |
11 |
Correct |
642 ms |
1120 KB |
Output is correct |
12 |
Correct |
1043 ms |
54944 KB |
Output is correct |
13 |
Correct |
1115 ms |
50976 KB |
Output is correct |
14 |
Correct |
564 ms |
3436 KB |
Output is correct |
15 |
Correct |
74 ms |
864 KB |
Output is correct |
16 |
Correct |
220 ms |
1040 KB |
Output is correct |
17 |
Correct |
640 ms |
1280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1124 ms |
864 KB |
Output is correct |
2 |
Correct |
749 ms |
1108 KB |
Output is correct |
3 |
Correct |
688 ms |
1004 KB |
Output is correct |
4 |
Correct |
3 ms |
1140 KB |
Output is correct |
5 |
Correct |
5 ms |
992 KB |
Output is correct |
6 |
Correct |
2 ms |
864 KB |
Output is correct |
7 |
Correct |
632 ms |
1104 KB |
Output is correct |
8 |
Correct |
977 ms |
1108 KB |
Output is correct |
9 |
Correct |
874 ms |
880 KB |
Output is correct |
10 |
Correct |
649 ms |
1016 KB |
Output is correct |
11 |
Correct |
5 ms |
1080 KB |
Output is correct |
12 |
Correct |
6 ms |
864 KB |
Output is correct |
13 |
Correct |
6 ms |
864 KB |
Output is correct |
14 |
Correct |
4 ms |
1080 KB |
Output is correct |
15 |
Correct |
2 ms |
864 KB |
Output is correct |
16 |
Correct |
529 ms |
1000 KB |
Output is correct |
17 |
Correct |
593 ms |
1120 KB |
Output is correct |
18 |
Correct |
551 ms |
864 KB |
Output is correct |
19 |
Correct |
628 ms |
1152 KB |
Output is correct |
20 |
Correct |
534 ms |
864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
959 ms |
56216 KB |
Output is correct |
2 |
Correct |
1093 ms |
49436 KB |
Output is correct |
3 |
Correct |
945 ms |
880 KB |
Output is correct |
4 |
Correct |
765 ms |
1108 KB |
Output is correct |
5 |
Correct |
690 ms |
992 KB |
Output is correct |
6 |
Correct |
1025 ms |
55904 KB |
Output is correct |
7 |
Correct |
540 ms |
31796 KB |
Output is correct |
8 |
Correct |
3 ms |
1096 KB |
Output is correct |
9 |
Correct |
5 ms |
1048 KB |
Output is correct |
10 |
Correct |
2 ms |
1108 KB |
Output is correct |
11 |
Correct |
1051 ms |
1380 KB |
Output is correct |
12 |
Correct |
628 ms |
1508 KB |
Output is correct |
13 |
Correct |
954 ms |
1016 KB |
Output is correct |
14 |
Correct |
741 ms |
880 KB |
Output is correct |
15 |
Correct |
648 ms |
992 KB |
Output is correct |
16 |
Correct |
514 ms |
1628 KB |
Output is correct |
17 |
Correct |
748 ms |
992 KB |
Output is correct |
18 |
Correct |
1057 ms |
37916 KB |
Output is correct |
19 |
Correct |
1081 ms |
52184 KB |
Output is correct |
20 |
Correct |
511 ms |
4868 KB |
Output is correct |
21 |
Correct |
71 ms |
1120 KB |
Output is correct |
22 |
Correct |
224 ms |
1128 KB |
Output is correct |
23 |
Correct |
611 ms |
1368 KB |
Output is correct |
24 |
Correct |
6 ms |
992 KB |
Output is correct |
25 |
Correct |
5 ms |
992 KB |
Output is correct |
26 |
Correct |
5 ms |
992 KB |
Output is correct |
27 |
Correct |
3 ms |
1088 KB |
Output is correct |
28 |
Correct |
2 ms |
1116 KB |
Output is correct |
29 |
Correct |
591 ms |
864 KB |
Output is correct |
30 |
Correct |
501 ms |
1144 KB |
Output is correct |
31 |
Correct |
546 ms |
992 KB |
Output is correct |
32 |
Correct |
464 ms |
992 KB |
Output is correct |
33 |
Correct |
493 ms |
992 KB |
Output is correct |
34 |
Correct |
881 ms |
42896 KB |
Output is correct |
35 |
Correct |
1104 ms |
56072 KB |
Output is correct |
36 |
Correct |
1157 ms |
46568 KB |
Output is correct |
37 |
Correct |
1082 ms |
14140 KB |
Output is correct |
38 |
Correct |
1183 ms |
14236 KB |
Output is correct |
39 |
Correct |
1115 ms |
18564 KB |
Output is correct |
40 |
Correct |
1071 ms |
18488 KB |
Output is correct |
41 |
Correct |
1076 ms |
15080 KB |
Output is correct |
42 |
Correct |
360 ms |
992 KB |
Output is correct |
43 |
Correct |
644 ms |
1120 KB |
Output is correct |
44 |
Correct |
604 ms |
1600 KB |
Output is correct |
45 |
Correct |
786 ms |
1888 KB |
Output is correct |
46 |
Correct |
736 ms |
16804 KB |
Output is correct |
47 |
Correct |
967 ms |
27300 KB |
Output is correct |
48 |
Correct |
524 ms |
1504 KB |
Output is correct |
49 |
Correct |
622 ms |
1956 KB |
Output is correct |