#include <bits/stdc++.h>
using namespace std;
vector<int> label(int n, int k, vector<int> u, vector<int> v){
vector<int> l(n);
vector<vector<int>> adj(n);
for(int i=0; i<n-1; i++){
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
int aux = 0;
function<void(int, int, int)> dfs = [&](int s, int e, int d){
if(d%2 == 0) l[s] = aux++;
for(auto u:adj[s])
if(u != e) dfs(u, s, d+1);
if(d%2 == 1) l[s] = aux++;
};
dfs(0, -1, 0);
return l;
}
int find_next_station(int s, int t, vector<int> c){
sort(c.begin(), c.end());
int n = c.size();
if(n == 1) return c[0]; //Out of bounds
if(s < c[0]){
if(t < s || t > c[n-2]) return c[n-1];
for(int i=0; i<n; i++)
if(c[i] >= t) return c[i];
} else {
if(t > s || t < c[1]) return c[0];
for(int i=2; i<n; i++)
if(c[i] > t) return c[i-1];
return c[n-1];
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:39:1: warning: control reaches end of non-void function [-Wreturn-type]
39 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
577 ms |
628 KB |
Output is correct |
2 |
Correct |
406 ms |
636 KB |
Output is correct |
3 |
Correct |
813 ms |
508 KB |
Output is correct |
4 |
Correct |
685 ms |
500 KB |
Output is correct |
5 |
Correct |
576 ms |
508 KB |
Output is correct |
6 |
Correct |
443 ms |
624 KB |
Output is correct |
7 |
Correct |
431 ms |
624 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
4 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
474 ms |
504 KB |
Output is correct |
2 |
Correct |
562 ms |
528 KB |
Output is correct |
3 |
Correct |
935 ms |
500 KB |
Output is correct |
4 |
Correct |
697 ms |
416 KB |
Output is correct |
5 |
Correct |
642 ms |
508 KB |
Output is correct |
6 |
Correct |
343 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
531 ms |
680 KB |
Output is correct |
2 |
Correct |
444 ms |
672 KB |
Output is correct |
3 |
Correct |
791 ms |
416 KB |
Output is correct |
4 |
Correct |
635 ms |
420 KB |
Output is correct |
5 |
Correct |
532 ms |
420 KB |
Output is correct |
6 |
Correct |
471 ms |
672 KB |
Output is correct |
7 |
Correct |
410 ms |
548 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
554 ms |
508 KB |
Output is correct |
12 |
Correct |
485 ms |
672 KB |
Output is correct |
13 |
Correct |
462 ms |
688 KB |
Output is correct |
14 |
Correct |
457 ms |
548 KB |
Output is correct |
15 |
Correct |
36 ms |
420 KB |
Output is correct |
16 |
Correct |
60 ms |
552 KB |
Output is correct |
17 |
Correct |
111 ms |
548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
861 ms |
416 KB |
Output is correct |
2 |
Correct |
658 ms |
416 KB |
Output is correct |
3 |
Correct |
589 ms |
416 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
4 ms |
500 KB |
Output is correct |
6 |
Correct |
1 ms |
500 KB |
Output is correct |
7 |
Correct |
556 ms |
504 KB |
Output is correct |
8 |
Correct |
911 ms |
500 KB |
Output is correct |
9 |
Correct |
610 ms |
504 KB |
Output is correct |
10 |
Correct |
594 ms |
504 KB |
Output is correct |
11 |
Correct |
4 ms |
508 KB |
Output is correct |
12 |
Correct |
5 ms |
492 KB |
Output is correct |
13 |
Correct |
5 ms |
492 KB |
Output is correct |
14 |
Correct |
2 ms |
492 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
444 ms |
504 KB |
Output is correct |
17 |
Correct |
481 ms |
416 KB |
Output is correct |
18 |
Correct |
499 ms |
416 KB |
Output is correct |
19 |
Correct |
525 ms |
416 KB |
Output is correct |
20 |
Correct |
543 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
532 ms |
628 KB |
Output is correct |
2 |
Correct |
467 ms |
548 KB |
Output is correct |
3 |
Correct |
917 ms |
416 KB |
Output is correct |
4 |
Correct |
540 ms |
640 KB |
Output is correct |
5 |
Correct |
601 ms |
508 KB |
Output is correct |
6 |
Correct |
429 ms |
760 KB |
Output is correct |
7 |
Correct |
422 ms |
628 KB |
Output is correct |
8 |
Correct |
1 ms |
500 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
492 KB |
Output is correct |
11 |
Correct |
464 ms |
508 KB |
Output is correct |
12 |
Correct |
552 ms |
512 KB |
Output is correct |
13 |
Correct |
804 ms |
416 KB |
Output is correct |
14 |
Correct |
705 ms |
416 KB |
Output is correct |
15 |
Correct |
568 ms |
420 KB |
Output is correct |
16 |
Correct |
435 ms |
548 KB |
Output is correct |
17 |
Correct |
547 ms |
420 KB |
Output is correct |
18 |
Correct |
451 ms |
716 KB |
Output is correct |
19 |
Correct |
476 ms |
712 KB |
Output is correct |
20 |
Correct |
420 ms |
560 KB |
Output is correct |
21 |
Correct |
57 ms |
416 KB |
Output is correct |
22 |
Correct |
73 ms |
564 KB |
Output is correct |
23 |
Correct |
87 ms |
544 KB |
Output is correct |
24 |
Correct |
5 ms |
500 KB |
Output is correct |
25 |
Correct |
4 ms |
492 KB |
Output is correct |
26 |
Correct |
5 ms |
492 KB |
Output is correct |
27 |
Correct |
2 ms |
492 KB |
Output is correct |
28 |
Correct |
2 ms |
492 KB |
Output is correct |
29 |
Correct |
511 ms |
504 KB |
Output is correct |
30 |
Correct |
543 ms |
416 KB |
Output is correct |
31 |
Correct |
505 ms |
420 KB |
Output is correct |
32 |
Correct |
500 ms |
416 KB |
Output is correct |
33 |
Correct |
523 ms |
500 KB |
Output is correct |
34 |
Correct |
317 ms |
672 KB |
Output is correct |
35 |
Correct |
461 ms |
660 KB |
Output is correct |
36 |
Correct |
410 ms |
752 KB |
Output is correct |
37 |
Correct |
459 ms |
628 KB |
Output is correct |
38 |
Correct |
438 ms |
632 KB |
Output is correct |
39 |
Correct |
440 ms |
664 KB |
Output is correct |
40 |
Correct |
417 ms |
848 KB |
Output is correct |
41 |
Correct |
431 ms |
668 KB |
Output is correct |
42 |
Correct |
52 ms |
548 KB |
Output is correct |
43 |
Correct |
108 ms |
676 KB |
Output is correct |
44 |
Correct |
129 ms |
544 KB |
Output is correct |
45 |
Correct |
165 ms |
544 KB |
Output is correct |
46 |
Correct |
289 ms |
548 KB |
Output is correct |
47 |
Correct |
286 ms |
628 KB |
Output is correct |
48 |
Correct |
57 ms |
544 KB |
Output is correct |
49 |
Correct |
59 ms |
692 KB |
Output is correct |