#include "stations.h"
#include <vector>
#include <algorithm>
using namespace std;
const int N = 1e3 + 10;
#define pb push_back
vector<int> ans;
int Time = 0;
vector<int> g[N];
void dfs(int u, int par, int t) {
if(!t) ans[u] = ++Time;
for(auto v : g[u]) {
if(v != par) {
dfs(v, u, t ^ 1);
}
}
if(t) ans[u] = ++Time;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
for(int i = 0; i < n; i++) g[i].clear();
Time = 0;
for(int i = 0; i < n - 1; i++) {
g[u[i]].pb(v[i]);
g[v[i]].pb(u[i]);
}
ans.resize(n);
dfs(0, -1, 0);
return ans;
}
int find_next_station(int s, int t, vector<int> c) {
sort(c.begin(), c.end());
if(c.size() == 1) return c[0];
if(s < c[0]) {
int ans = c[0];
if(t < s) return c.back();
for(int i = 0; i < c.size() - 1; i++) {
if(t > c[i]) ans = c[i + 1];
}
return ans;
} else {
int ans = c[0];
if(t > s) return c[0];
for(int i = 1; i < c.size(); i++) {
if(t >= c[i]) ans = c[i];
}
return ans;
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int i = 0; i < c.size() - 1; i++) {
| ~~^~~~~~~~~~~~~~
stations.cpp:49:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for(int i = 1; i < c.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
549 ms |
648 KB |
Output is correct |
2 |
Correct |
433 ms |
644 KB |
Output is correct |
3 |
Correct |
880 ms |
420 KB |
Output is correct |
4 |
Correct |
624 ms |
516 KB |
Output is correct |
5 |
Correct |
573 ms |
420 KB |
Output is correct |
6 |
Correct |
450 ms |
548 KB |
Output is correct |
7 |
Correct |
464 ms |
496 KB |
Output is correct |
8 |
Correct |
1 ms |
500 KB |
Output is correct |
9 |
Correct |
3 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
366 ms |
524 KB |
Output is correct |
2 |
Correct |
533 ms |
532 KB |
Output is correct |
3 |
Correct |
966 ms |
524 KB |
Output is correct |
4 |
Correct |
640 ms |
520 KB |
Output is correct |
5 |
Correct |
585 ms |
516 KB |
Output is correct |
6 |
Correct |
462 ms |
516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
561 ms |
644 KB |
Output is correct |
2 |
Correct |
442 ms |
640 KB |
Output is correct |
3 |
Correct |
900 ms |
420 KB |
Output is correct |
4 |
Correct |
795 ms |
516 KB |
Output is correct |
5 |
Correct |
553 ms |
508 KB |
Output is correct |
6 |
Correct |
528 ms |
508 KB |
Output is correct |
7 |
Correct |
553 ms |
516 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
5 ms |
496 KB |
Output is correct |
10 |
Correct |
1 ms |
500 KB |
Output is correct |
11 |
Correct |
545 ms |
516 KB |
Output is correct |
12 |
Correct |
473 ms |
728 KB |
Output is correct |
13 |
Correct |
502 ms |
676 KB |
Output is correct |
14 |
Correct |
457 ms |
508 KB |
Output is correct |
15 |
Correct |
53 ms |
472 KB |
Output is correct |
16 |
Correct |
63 ms |
548 KB |
Output is correct |
17 |
Correct |
90 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
810 ms |
416 KB |
Output is correct |
2 |
Correct |
639 ms |
416 KB |
Output is correct |
3 |
Correct |
556 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
500 KB |
Output is correct |
5 |
Correct |
3 ms |
420 KB |
Output is correct |
6 |
Correct |
1 ms |
500 KB |
Output is correct |
7 |
Correct |
555 ms |
524 KB |
Output is correct |
8 |
Correct |
881 ms |
416 KB |
Output is correct |
9 |
Correct |
623 ms |
416 KB |
Output is correct |
10 |
Correct |
534 ms |
516 KB |
Output is correct |
11 |
Correct |
4 ms |
492 KB |
Output is correct |
12 |
Correct |
5 ms |
492 KB |
Output is correct |
13 |
Correct |
5 ms |
492 KB |
Output is correct |
14 |
Correct |
4 ms |
524 KB |
Output is correct |
15 |
Correct |
2 ms |
500 KB |
Output is correct |
16 |
Correct |
450 ms |
512 KB |
Output is correct |
17 |
Correct |
525 ms |
420 KB |
Output is correct |
18 |
Correct |
466 ms |
416 KB |
Output is correct |
19 |
Correct |
431 ms |
512 KB |
Output is correct |
20 |
Correct |
546 ms |
420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
483 ms |
544 KB |
Output is correct |
2 |
Correct |
515 ms |
636 KB |
Output is correct |
3 |
Correct |
748 ms |
416 KB |
Output is correct |
4 |
Correct |
529 ms |
524 KB |
Output is correct |
5 |
Correct |
619 ms |
524 KB |
Output is correct |
6 |
Correct |
466 ms |
644 KB |
Output is correct |
7 |
Correct |
418 ms |
548 KB |
Output is correct |
8 |
Correct |
3 ms |
480 KB |
Output is correct |
9 |
Correct |
3 ms |
500 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
397 ms |
512 KB |
Output is correct |
12 |
Correct |
505 ms |
544 KB |
Output is correct |
13 |
Correct |
839 ms |
416 KB |
Output is correct |
14 |
Correct |
608 ms |
512 KB |
Output is correct |
15 |
Correct |
660 ms |
520 KB |
Output is correct |
16 |
Correct |
459 ms |
544 KB |
Output is correct |
17 |
Correct |
600 ms |
416 KB |
Output is correct |
18 |
Correct |
378 ms |
636 KB |
Output is correct |
19 |
Correct |
445 ms |
640 KB |
Output is correct |
20 |
Correct |
447 ms |
544 KB |
Output is correct |
21 |
Correct |
55 ms |
428 KB |
Output is correct |
22 |
Correct |
66 ms |
544 KB |
Output is correct |
23 |
Correct |
69 ms |
568 KB |
Output is correct |
24 |
Correct |
4 ms |
492 KB |
Output is correct |
25 |
Correct |
4 ms |
500 KB |
Output is correct |
26 |
Correct |
4 ms |
492 KB |
Output is correct |
27 |
Correct |
2 ms |
500 KB |
Output is correct |
28 |
Correct |
2 ms |
500 KB |
Output is correct |
29 |
Correct |
520 ms |
512 KB |
Output is correct |
30 |
Correct |
443 ms |
520 KB |
Output is correct |
31 |
Correct |
347 ms |
516 KB |
Output is correct |
32 |
Correct |
520 ms |
420 KB |
Output is correct |
33 |
Correct |
525 ms |
512 KB |
Output is correct |
34 |
Correct |
337 ms |
524 KB |
Output is correct |
35 |
Correct |
394 ms |
652 KB |
Output is correct |
36 |
Correct |
436 ms |
544 KB |
Output is correct |
37 |
Correct |
452 ms |
672 KB |
Output is correct |
38 |
Correct |
618 ms |
604 KB |
Output is correct |
39 |
Correct |
529 ms |
592 KB |
Output is correct |
40 |
Correct |
548 ms |
640 KB |
Output is correct |
41 |
Correct |
498 ms |
608 KB |
Output is correct |
42 |
Correct |
54 ms |
544 KB |
Output is correct |
43 |
Correct |
106 ms |
548 KB |
Output is correct |
44 |
Correct |
131 ms |
516 KB |
Output is correct |
45 |
Correct |
168 ms |
520 KB |
Output is correct |
46 |
Correct |
322 ms |
544 KB |
Output is correct |
47 |
Correct |
309 ms |
616 KB |
Output is correct |
48 |
Correct |
63 ms |
664 KB |
Output is correct |
49 |
Correct |
57 ms |
648 KB |
Output is correct |