#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int nextnum;
int arr[1005];
vector<int> pairs[1005];
void dfs(int par, int a, int dep){
if(dep%2){
arr[a] = nextnum;
nextnum++;
}
for(int i:pairs[a]){
if(i!=par){
dfs(a,i,dep+1);
}
}
if(dep%2==0){
arr[a] = nextnum;
nextnum++;
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v){
nextnum = 0;
for(int i=0;i<n;i++){
pairs[i].clear();
}
for(int i=0;i<n-1;i++){
pairs[u[i]].push_back(v[i]);
pairs[v[i]].push_back(u[i]);
}
dfs(-1,0,1);
vector<int> ans;
for(int i=0;i<n;i++){
ans.push_back(arr[i]);
}
return ans;
}
int find_next_station(int s, int t, vector<int> c){
sort(c.begin(),c.end());
if(s==0){
for(int i:c){
if(t<=i){
return i;
}
}
}
else if(c.size()==1){
return c[0];
}
else{
if(c[0]<s){
if(s<t){
return c[0];
}
reverse(c.begin(),c.end());
for(int i=0;i<c.size()-1;i++){
if(c[i]<=t){
return c[i];
}
}
return c[c.size()-1];
}
else{
if(s>t){
return c[c.size()-1];
}
for(int i=0;i<c.size()-1;i++){
if(c[i]>=t){
return c[i];
}
}
return c[c.size()-1];
}
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:61:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for(int i=0;i<c.size()-1;i++){
| ~^~~~~~~~~~~
stations.cpp:72:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for(int i=0;i<c.size()-1;i++){
| ~^~~~~~~~~~~
stations.cpp:80:1: warning: control reaches end of non-void function [-Wreturn-type]
80 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
670 ms |
660 KB |
Output is correct |
2 |
Correct |
541 ms |
636 KB |
Output is correct |
3 |
Correct |
1005 ms |
492 KB |
Output is correct |
4 |
Correct |
723 ms |
584 KB |
Output is correct |
5 |
Correct |
724 ms |
400 KB |
Output is correct |
6 |
Correct |
567 ms |
512 KB |
Output is correct |
7 |
Correct |
567 ms |
508 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
5 ms |
480 KB |
Output is correct |
10 |
Correct |
2 ms |
464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
495 ms |
508 KB |
Output is correct |
2 |
Correct |
562 ms |
528 KB |
Output is correct |
3 |
Correct |
969 ms |
520 KB |
Output is correct |
4 |
Correct |
719 ms |
400 KB |
Output is correct |
5 |
Correct |
670 ms |
528 KB |
Output is correct |
6 |
Correct |
468 ms |
532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
624 ms |
520 KB |
Output is correct |
2 |
Correct |
508 ms |
640 KB |
Output is correct |
3 |
Correct |
1057 ms |
412 KB |
Output is correct |
4 |
Correct |
741 ms |
508 KB |
Output is correct |
5 |
Correct |
741 ms |
400 KB |
Output is correct |
6 |
Correct |
493 ms |
528 KB |
Output is correct |
7 |
Correct |
568 ms |
528 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
476 KB |
Output is correct |
10 |
Correct |
1 ms |
472 KB |
Output is correct |
11 |
Correct |
681 ms |
552 KB |
Output is correct |
12 |
Correct |
541 ms |
624 KB |
Output is correct |
13 |
Correct |
583 ms |
760 KB |
Output is correct |
14 |
Correct |
504 ms |
528 KB |
Output is correct |
15 |
Correct |
54 ms |
576 KB |
Output is correct |
16 |
Correct |
78 ms |
696 KB |
Output is correct |
17 |
Correct |
120 ms |
804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1023 ms |
516 KB |
Output is correct |
2 |
Correct |
741 ms |
400 KB |
Output is correct |
3 |
Correct |
719 ms |
528 KB |
Output is correct |
4 |
Correct |
3 ms |
476 KB |
Output is correct |
5 |
Correct |
5 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
480 KB |
Output is correct |
7 |
Correct |
617 ms |
516 KB |
Output is correct |
8 |
Correct |
967 ms |
516 KB |
Output is correct |
9 |
Correct |
804 ms |
508 KB |
Output is correct |
10 |
Correct |
730 ms |
400 KB |
Output is correct |
11 |
Correct |
6 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
480 KB |
Output is correct |
13 |
Correct |
6 ms |
468 KB |
Output is correct |
14 |
Correct |
4 ms |
476 KB |
Output is correct |
15 |
Correct |
2 ms |
472 KB |
Output is correct |
16 |
Correct |
581 ms |
400 KB |
Output is correct |
17 |
Correct |
650 ms |
540 KB |
Output is correct |
18 |
Correct |
501 ms |
400 KB |
Output is correct |
19 |
Correct |
610 ms |
400 KB |
Output is correct |
20 |
Correct |
475 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
551 ms |
528 KB |
Output is correct |
2 |
Correct |
507 ms |
520 KB |
Output is correct |
3 |
Correct |
1029 ms |
528 KB |
Output is correct |
4 |
Correct |
717 ms |
400 KB |
Output is correct |
5 |
Correct |
727 ms |
400 KB |
Output is correct |
6 |
Correct |
496 ms |
632 KB |
Output is correct |
7 |
Correct |
493 ms |
528 KB |
Output is correct |
8 |
Correct |
3 ms |
476 KB |
Output is correct |
9 |
Correct |
6 ms |
584 KB |
Output is correct |
10 |
Correct |
2 ms |
400 KB |
Output is correct |
11 |
Correct |
568 ms |
500 KB |
Output is correct |
12 |
Correct |
518 ms |
536 KB |
Output is correct |
13 |
Correct |
970 ms |
400 KB |
Output is correct |
14 |
Correct |
855 ms |
640 KB |
Output is correct |
15 |
Correct |
626 ms |
400 KB |
Output is correct |
16 |
Correct |
491 ms |
520 KB |
Output is correct |
17 |
Correct |
621 ms |
504 KB |
Output is correct |
18 |
Correct |
578 ms |
632 KB |
Output is correct |
19 |
Correct |
479 ms |
640 KB |
Output is correct |
20 |
Correct |
498 ms |
492 KB |
Output is correct |
21 |
Correct |
58 ms |
416 KB |
Output is correct |
22 |
Correct |
84 ms |
656 KB |
Output is correct |
23 |
Correct |
111 ms |
680 KB |
Output is correct |
24 |
Correct |
5 ms |
468 KB |
Output is correct |
25 |
Correct |
6 ms |
476 KB |
Output is correct |
26 |
Correct |
4 ms |
468 KB |
Output is correct |
27 |
Correct |
3 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
472 KB |
Output is correct |
29 |
Correct |
659 ms |
512 KB |
Output is correct |
30 |
Correct |
516 ms |
400 KB |
Output is correct |
31 |
Correct |
510 ms |
400 KB |
Output is correct |
32 |
Correct |
616 ms |
512 KB |
Output is correct |
33 |
Correct |
565 ms |
528 KB |
Output is correct |
34 |
Correct |
395 ms |
528 KB |
Output is correct |
35 |
Correct |
474 ms |
888 KB |
Output is correct |
36 |
Correct |
464 ms |
624 KB |
Output is correct |
37 |
Correct |
534 ms |
596 KB |
Output is correct |
38 |
Correct |
462 ms |
648 KB |
Output is correct |
39 |
Correct |
450 ms |
632 KB |
Output is correct |
40 |
Correct |
566 ms |
716 KB |
Output is correct |
41 |
Correct |
471 ms |
756 KB |
Output is correct |
42 |
Correct |
75 ms |
528 KB |
Output is correct |
43 |
Correct |
120 ms |
544 KB |
Output is correct |
44 |
Correct |
153 ms |
604 KB |
Output is correct |
45 |
Correct |
172 ms |
528 KB |
Output is correct |
46 |
Correct |
332 ms |
656 KB |
Output is correct |
47 |
Correct |
356 ms |
636 KB |
Output is correct |
48 |
Correct |
55 ms |
720 KB |
Output is correct |
49 |
Correct |
77 ms |
656 KB |
Output is correct |