#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++){
cout<<ans[i]<<endl;
}*/
for(i=0; i<n; i++) label[i]=ans[i];
//ans.clear(); a.clear();
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];
}
//cout<<"ans"<<ans<<endl;
//if(ans==s)
//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:44:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int i=1; i<c.size()-1; i++){
| ~^~~~~~~~~~~
stations.cpp:51:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(int i=1; i<c.size()-1; i++){
| ~^~~~~~~~~~~
stations.cpp:39:7: warning: unused variable 'parent' [-Wunused-variable]
39 | bool parent=true;
| ^~~~~~
stations.cpp:40:6: warning: unused variable 'ans' [-Wunused-variable]
40 | int ans;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
999 ms |
55944 KB |
Output is correct |
2 |
Correct |
1137 ms |
55668 KB |
Output is correct |
3 |
Correct |
959 ms |
864 KB |
Output is correct |
4 |
Correct |
632 ms |
1108 KB |
Output is correct |
5 |
Correct |
674 ms |
864 KB |
Output is correct |
6 |
Correct |
1061 ms |
49908 KB |
Output is correct |
7 |
Correct |
549 ms |
42124 KB |
Output is correct |
8 |
Correct |
3 ms |
992 KB |
Output is correct |
9 |
Correct |
4 ms |
864 KB |
Output is correct |
10 |
Correct |
2 ms |
864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1051 ms |
1380 KB |
Output is correct |
2 |
Correct |
655 ms |
1632 KB |
Output is correct |
3 |
Correct |
988 ms |
880 KB |
Output is correct |
4 |
Correct |
644 ms |
864 KB |
Output is correct |
5 |
Correct |
620 ms |
1116 KB |
Output is correct |
6 |
Correct |
645 ms |
1628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1050 ms |
55980 KB |
Output is correct |
2 |
Correct |
1065 ms |
54128 KB |
Output is correct |
3 |
Correct |
952 ms |
880 KB |
Output is correct |
4 |
Correct |
670 ms |
864 KB |
Output is correct |
5 |
Correct |
806 ms |
992 KB |
Output is correct |
6 |
Correct |
1135 ms |
53948 KB |
Output is correct |
7 |
Correct |
575 ms |
42988 KB |
Output is correct |
8 |
Correct |
3 ms |
1088 KB |
Output is correct |
9 |
Correct |
5 ms |
992 KB |
Output is correct |
10 |
Correct |
2 ms |
992 KB |
Output is correct |
11 |
Correct |
655 ms |
1108 KB |
Output is correct |
12 |
Correct |
1072 ms |
55008 KB |
Output is correct |
13 |
Correct |
1078 ms |
50888 KB |
Output is correct |
14 |
Correct |
544 ms |
3428 KB |
Output is correct |
15 |
Correct |
80 ms |
1108 KB |
Output is correct |
16 |
Correct |
248 ms |
1000 KB |
Output is correct |
17 |
Correct |
602 ms |
1092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
965 ms |
992 KB |
Output is correct |
2 |
Correct |
764 ms |
1108 KB |
Output is correct |
3 |
Correct |
738 ms |
972 KB |
Output is correct |
4 |
Correct |
3 ms |
1088 KB |
Output is correct |
5 |
Correct |
4 ms |
1036 KB |
Output is correct |
6 |
Correct |
2 ms |
1108 KB |
Output is correct |
7 |
Correct |
638 ms |
1104 KB |
Output is correct |
8 |
Correct |
1013 ms |
992 KB |
Output is correct |
9 |
Correct |
778 ms |
1120 KB |
Output is correct |
10 |
Correct |
661 ms |
1108 KB |
Output is correct |
11 |
Correct |
6 ms |
1132 KB |
Output is correct |
12 |
Correct |
6 ms |
1044 KB |
Output is correct |
13 |
Correct |
5 ms |
992 KB |
Output is correct |
14 |
Correct |
4 ms |
1132 KB |
Output is correct |
15 |
Correct |
2 ms |
992 KB |
Output is correct |
16 |
Correct |
664 ms |
992 KB |
Output is correct |
17 |
Correct |
540 ms |
992 KB |
Output is correct |
18 |
Correct |
572 ms |
1012 KB |
Output is correct |
19 |
Correct |
602 ms |
1012 KB |
Output is correct |
20 |
Correct |
527 ms |
992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
962 ms |
55904 KB |
Output is correct |
2 |
Correct |
1096 ms |
49556 KB |
Output is correct |
3 |
Correct |
1000 ms |
1008 KB |
Output is correct |
4 |
Correct |
811 ms |
1108 KB |
Output is correct |
5 |
Correct |
643 ms |
864 KB |
Output is correct |
6 |
Correct |
1056 ms |
56068 KB |
Output is correct |
7 |
Correct |
668 ms |
31584 KB |
Output is correct |
8 |
Correct |
3 ms |
992 KB |
Output is correct |
9 |
Correct |
4 ms |
1040 KB |
Output is correct |
10 |
Correct |
2 ms |
992 KB |
Output is correct |
11 |
Correct |
967 ms |
1600 KB |
Output is correct |
12 |
Correct |
644 ms |
1448 KB |
Output is correct |
13 |
Correct |
966 ms |
864 KB |
Output is correct |
14 |
Correct |
776 ms |
864 KB |
Output is correct |
15 |
Correct |
615 ms |
1116 KB |
Output is correct |
16 |
Correct |
583 ms |
1636 KB |
Output is correct |
17 |
Correct |
662 ms |
1088 KB |
Output is correct |
18 |
Correct |
1088 ms |
37856 KB |
Output is correct |
19 |
Correct |
1093 ms |
52320 KB |
Output is correct |
20 |
Correct |
531 ms |
4824 KB |
Output is correct |
21 |
Correct |
60 ms |
1232 KB |
Output is correct |
22 |
Correct |
232 ms |
864 KB |
Output is correct |
23 |
Correct |
650 ms |
1248 KB |
Output is correct |
24 |
Correct |
6 ms |
992 KB |
Output is correct |
25 |
Correct |
6 ms |
864 KB |
Output is correct |
26 |
Correct |
5 ms |
864 KB |
Output is correct |
27 |
Correct |
4 ms |
864 KB |
Output is correct |
28 |
Correct |
2 ms |
864 KB |
Output is correct |
29 |
Correct |
571 ms |
992 KB |
Output is correct |
30 |
Correct |
577 ms |
1016 KB |
Output is correct |
31 |
Correct |
551 ms |
1048 KB |
Output is correct |
32 |
Correct |
507 ms |
992 KB |
Output is correct |
33 |
Correct |
630 ms |
992 KB |
Output is correct |
34 |
Correct |
967 ms |
42804 KB |
Output is correct |
35 |
Correct |
1042 ms |
56032 KB |
Output is correct |
36 |
Correct |
1089 ms |
46744 KB |
Output is correct |
37 |
Correct |
1181 ms |
14256 KB |
Output is correct |
38 |
Correct |
1230 ms |
14176 KB |
Output is correct |
39 |
Correct |
1222 ms |
18444 KB |
Output is correct |
40 |
Correct |
1128 ms |
18352 KB |
Output is correct |
41 |
Correct |
1097 ms |
15064 KB |
Output is correct |
42 |
Correct |
376 ms |
1120 KB |
Output is correct |
43 |
Correct |
623 ms |
1248 KB |
Output is correct |
44 |
Correct |
611 ms |
1592 KB |
Output is correct |
45 |
Correct |
721 ms |
2112 KB |
Output is correct |
46 |
Correct |
703 ms |
16924 KB |
Output is correct |
47 |
Correct |
1054 ms |
27220 KB |
Output is correct |
48 |
Correct |
541 ms |
1632 KB |
Output is correct |
49 |
Correct |
637 ms |
1644 KB |
Output is correct |