#include <bits/stdc++.h>
#include "stations.h"
using namespace std;
vector<int>adj[1005];
vector<int>l;
int curr = 0;
void dfs(int u, bool f, int e = -1) {
if(f)
l[u] = curr++;
for(auto z : adj[u]) if(z != e) {
dfs(z, 1 - f, u);
}
if(!f)
l[u] = curr++;
}
vector<int>label(int n, int k, vector<int>u, vector<int>v) {
l.resize(n, -1);
curr = 0;
for(int i = 0 ; i < n ; i++)
adj[i].clear();
for(int i = 0 ; i < (int)u.size() ; i++) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
dfs(0, 1);
for(auto z : l)
assert(z != -1);
return l;
}
int find_next_station(int s, int t, vector<int>c) {
if(c.size() == 1)
return c[0];
if(s == 0) {
for(int i = 0 ; i < c.size() ; i++) {
if(t >= s && t <= c[i])
return c[i];
}
}
if(s < c[0]) {
if(t <= c.back() && t <= s)
return c.back();
if(t >= c.back() && t >= s)
return c.back();
for(int i = 0 ; i < c.size()-1 ; i++) {
if(t >= s && t <= c[i])
return c[i];
}
} else {
if(t <= c[0] && t <= s)
return c[0];
if(t >= c[0] && t >= s)
return c[0];
for(int i = c.size()-1 ; i > 0 ; i--) {
if(t <= s && t >= c[i])
return c[i];
}
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:47:27: 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 = 0 ; i < c.size() ; i++) {
| ~~^~~~~~~~~~
stations.cpp:60:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for(int i = 0 ; i < c.size()-1 ; i++) {
| ~~^~~~~~~~~~~~
stations.cpp:76:1: warning: control reaches end of non-void function [-Wreturn-type]
76 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
527 ms |
548 KB |
Output is correct |
2 |
Correct |
492 ms |
668 KB |
Output is correct |
3 |
Correct |
778 ms |
532 KB |
Output is correct |
4 |
Correct |
555 ms |
416 KB |
Output is correct |
5 |
Correct |
667 ms |
484 KB |
Output is correct |
6 |
Correct |
461 ms |
656 KB |
Output is correct |
7 |
Correct |
442 ms |
524 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
5 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
455 ms |
588 KB |
Output is correct |
2 |
Correct |
550 ms |
528 KB |
Output is correct |
3 |
Correct |
815 ms |
416 KB |
Output is correct |
4 |
Correct |
728 ms |
420 KB |
Output is correct |
5 |
Correct |
593 ms |
528 KB |
Output is correct |
6 |
Correct |
433 ms |
544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
601 ms |
676 KB |
Output is correct |
2 |
Correct |
427 ms |
656 KB |
Output is correct |
3 |
Correct |
800 ms |
528 KB |
Output is correct |
4 |
Correct |
617 ms |
592 KB |
Output is correct |
5 |
Correct |
569 ms |
528 KB |
Output is correct |
6 |
Correct |
427 ms |
524 KB |
Output is correct |
7 |
Correct |
427 ms |
516 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
3 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
492 KB |
Output is correct |
11 |
Correct |
520 ms |
532 KB |
Output is correct |
12 |
Correct |
455 ms |
764 KB |
Output is correct |
13 |
Correct |
449 ms |
624 KB |
Output is correct |
14 |
Correct |
427 ms |
548 KB |
Output is correct |
15 |
Correct |
50 ms |
600 KB |
Output is correct |
16 |
Correct |
59 ms |
572 KB |
Output is correct |
17 |
Correct |
92 ms |
548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
839 ms |
528 KB |
Output is correct |
2 |
Correct |
617 ms |
420 KB |
Output is correct |
3 |
Correct |
706 ms |
640 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
3 ms |
496 KB |
Output is correct |
6 |
Correct |
1 ms |
500 KB |
Output is correct |
7 |
Correct |
605 ms |
416 KB |
Output is correct |
8 |
Correct |
996 ms |
416 KB |
Output is correct |
9 |
Correct |
600 ms |
532 KB |
Output is correct |
10 |
Correct |
657 ms |
524 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
7 ms |
480 KB |
Output is correct |
13 |
Correct |
5 ms |
492 KB |
Output is correct |
14 |
Correct |
4 ms |
492 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
648 ms |
416 KB |
Output is correct |
17 |
Correct |
483 ms |
524 KB |
Output is correct |
18 |
Correct |
639 ms |
420 KB |
Output is correct |
19 |
Correct |
498 ms |
528 KB |
Output is correct |
20 |
Correct |
447 ms |
516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
435 ms |
656 KB |
Output is correct |
2 |
Correct |
428 ms |
688 KB |
Output is correct |
3 |
Correct |
859 ms |
416 KB |
Output is correct |
4 |
Correct |
622 ms |
420 KB |
Output is correct |
5 |
Correct |
501 ms |
556 KB |
Output is correct |
6 |
Correct |
435 ms |
540 KB |
Output is correct |
7 |
Correct |
398 ms |
524 KB |
Output is correct |
8 |
Correct |
2 ms |
496 KB |
Output is correct |
9 |
Correct |
4 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
492 ms |
524 KB |
Output is correct |
12 |
Correct |
541 ms |
520 KB |
Output is correct |
13 |
Correct |
777 ms |
416 KB |
Output is correct |
14 |
Correct |
659 ms |
524 KB |
Output is correct |
15 |
Correct |
584 ms |
416 KB |
Output is correct |
16 |
Correct |
458 ms |
532 KB |
Output is correct |
17 |
Correct |
572 ms |
416 KB |
Output is correct |
18 |
Correct |
436 ms |
628 KB |
Output is correct |
19 |
Correct |
427 ms |
788 KB |
Output is correct |
20 |
Correct |
450 ms |
552 KB |
Output is correct |
21 |
Correct |
50 ms |
572 KB |
Output is correct |
22 |
Correct |
58 ms |
572 KB |
Output is correct |
23 |
Correct |
104 ms |
544 KB |
Output is correct |
24 |
Correct |
4 ms |
492 KB |
Output is correct |
25 |
Correct |
4 ms |
500 KB |
Output is correct |
26 |
Correct |
3 ms |
492 KB |
Output is correct |
27 |
Correct |
3 ms |
556 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
556 ms |
524 KB |
Output is correct |
30 |
Correct |
520 ms |
532 KB |
Output is correct |
31 |
Correct |
439 ms |
416 KB |
Output is correct |
32 |
Correct |
407 ms |
416 KB |
Output is correct |
33 |
Correct |
464 ms |
528 KB |
Output is correct |
34 |
Correct |
308 ms |
548 KB |
Output is correct |
35 |
Correct |
421 ms |
656 KB |
Output is correct |
36 |
Correct |
473 ms |
740 KB |
Output is correct |
37 |
Correct |
529 ms |
656 KB |
Output is correct |
38 |
Correct |
459 ms |
648 KB |
Output is correct |
39 |
Correct |
414 ms |
852 KB |
Output is correct |
40 |
Correct |
319 ms |
652 KB |
Output is correct |
41 |
Correct |
402 ms |
632 KB |
Output is correct |
42 |
Correct |
51 ms |
692 KB |
Output is correct |
43 |
Correct |
102 ms |
656 KB |
Output is correct |
44 |
Correct |
130 ms |
536 KB |
Output is correct |
45 |
Correct |
131 ms |
524 KB |
Output is correct |
46 |
Correct |
264 ms |
548 KB |
Output is correct |
47 |
Correct |
322 ms |
624 KB |
Output is correct |
48 |
Correct |
51 ms |
748 KB |
Output is correct |
49 |
Correct |
55 ms |
700 KB |
Output is correct |