#include "stations.h"
#include "bits/stdc++.h"
using namespace std;
#define sz(a) (int)a.size()
const int N = 1000;
vector<int> adj[N];
int in[N], out[N], tt = 0, depth[N];
void dfs(int u, int par) {
in[u] = tt++;
for(int v: adj[u]) {
if(v == par) continue;
depth[v] = depth[u] ^ 1;
dfs(v, u);
}
out[u] = tt++;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
std::vector<int> labels(n);
for(int i = 0; i < n; ++i) {
adj[i].clear();
tt = 0;
out[i] = 0, in[i] = 0;
}
for(int i = 0; i < n - 1; ++i) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
dfs(0, -1);
for (int i = 0; i < n; i++) {
labels[i] = (depth[i] ? out[i] : in[i]);
}
vector<int> b = labels;
sort(b.begin(), b.end());
for(int i = 0; i < n; ++i) {
labels[i] = lower_bound(b.begin(), b.end(), labels[i]) - b.begin();
}
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
int in_s, out_s;
bool dd = 0;
if(s == 0) {
in_s = 0;
out_s = c.back() + 1;
} else {
if(s < c[0]) {
dd = 0;
in_s = s;
if(sz(c) >= 2) out_s = c[sz(c) - 2] + 1;
else out_s = in_s;
} else {
dd = 1;
out_s = s;
if(sz(c) >= 2) in_s = c[1] - 1;
else in_s = out_s;
}
}
if(dd == 0) {
if(in_s <= t && t <= out_s) {
for(auto x: c) {
if(x >= t) return x;
}
} else return c.back();
} else {
if(in_s <= t && t <= out_s) {
reverse(c.begin(), c.end());
for(auto x: c) {
if(x <= t) return x;
}
} else return c[0];
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:75:1: warning: control reaches end of non-void function [-Wreturn-type]
75 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
549 ms |
544 KB |
Output is correct |
2 |
Correct |
458 ms |
668 KB |
Output is correct |
3 |
Correct |
951 ms |
416 KB |
Output is correct |
4 |
Correct |
596 ms |
420 KB |
Output is correct |
5 |
Correct |
677 ms |
520 KB |
Output is correct |
6 |
Correct |
418 ms |
676 KB |
Output is correct |
7 |
Correct |
473 ms |
532 KB |
Output is correct |
8 |
Correct |
2 ms |
628 KB |
Output is correct |
9 |
Correct |
4 ms |
628 KB |
Output is correct |
10 |
Correct |
0 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
404 ms |
528 KB |
Output is correct |
2 |
Correct |
615 ms |
524 KB |
Output is correct |
3 |
Correct |
898 ms |
416 KB |
Output is correct |
4 |
Correct |
778 ms |
544 KB |
Output is correct |
5 |
Correct |
603 ms |
536 KB |
Output is correct |
6 |
Correct |
380 ms |
536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
559 ms |
704 KB |
Output is correct |
2 |
Correct |
435 ms |
544 KB |
Output is correct |
3 |
Correct |
947 ms |
544 KB |
Output is correct |
4 |
Correct |
582 ms |
524 KB |
Output is correct |
5 |
Correct |
541 ms |
548 KB |
Output is correct |
6 |
Correct |
395 ms |
528 KB |
Output is correct |
7 |
Correct |
396 ms |
548 KB |
Output is correct |
8 |
Correct |
2 ms |
620 KB |
Output is correct |
9 |
Correct |
5 ms |
608 KB |
Output is correct |
10 |
Correct |
2 ms |
624 KB |
Output is correct |
11 |
Correct |
636 ms |
532 KB |
Output is correct |
12 |
Correct |
583 ms |
648 KB |
Output is correct |
13 |
Correct |
477 ms |
636 KB |
Output is correct |
14 |
Correct |
398 ms |
540 KB |
Output is correct |
15 |
Correct |
59 ms |
596 KB |
Output is correct |
16 |
Correct |
64 ms |
536 KB |
Output is correct |
17 |
Correct |
147 ms |
732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
743 ms |
532 KB |
Output is correct |
2 |
Correct |
536 ms |
548 KB |
Output is correct |
3 |
Correct |
593 ms |
532 KB |
Output is correct |
4 |
Correct |
4 ms |
620 KB |
Output is correct |
5 |
Correct |
4 ms |
628 KB |
Output is correct |
6 |
Correct |
2 ms |
620 KB |
Output is correct |
7 |
Correct |
678 ms |
532 KB |
Output is correct |
8 |
Correct |
820 ms |
612 KB |
Output is correct |
9 |
Correct |
567 ms |
532 KB |
Output is correct |
10 |
Correct |
525 ms |
444 KB |
Output is correct |
11 |
Correct |
3 ms |
620 KB |
Output is correct |
12 |
Correct |
3 ms |
620 KB |
Output is correct |
13 |
Correct |
4 ms |
620 KB |
Output is correct |
14 |
Correct |
3 ms |
628 KB |
Output is correct |
15 |
Correct |
2 ms |
620 KB |
Output is correct |
16 |
Correct |
523 ms |
536 KB |
Output is correct |
17 |
Correct |
560 ms |
536 KB |
Output is correct |
18 |
Correct |
524 ms |
536 KB |
Output is correct |
19 |
Correct |
477 ms |
532 KB |
Output is correct |
20 |
Correct |
497 ms |
536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
578 ms |
644 KB |
Output is correct |
2 |
Correct |
412 ms |
532 KB |
Output is correct |
3 |
Correct |
952 ms |
416 KB |
Output is correct |
4 |
Correct |
675 ms |
544 KB |
Output is correct |
5 |
Correct |
695 ms |
548 KB |
Output is correct |
6 |
Correct |
514 ms |
664 KB |
Output is correct |
7 |
Correct |
338 ms |
544 KB |
Output is correct |
8 |
Correct |
3 ms |
620 KB |
Output is correct |
9 |
Correct |
3 ms |
620 KB |
Output is correct |
10 |
Correct |
2 ms |
620 KB |
Output is correct |
11 |
Correct |
600 ms |
548 KB |
Output is correct |
12 |
Correct |
559 ms |
528 KB |
Output is correct |
13 |
Correct |
937 ms |
528 KB |
Output is correct |
14 |
Correct |
540 ms |
536 KB |
Output is correct |
15 |
Correct |
543 ms |
416 KB |
Output is correct |
16 |
Correct |
483 ms |
528 KB |
Output is correct |
17 |
Correct |
573 ms |
540 KB |
Output is correct |
18 |
Correct |
381 ms |
620 KB |
Output is correct |
19 |
Correct |
426 ms |
664 KB |
Output is correct |
20 |
Correct |
411 ms |
544 KB |
Output is correct |
21 |
Correct |
50 ms |
620 KB |
Output is correct |
22 |
Correct |
73 ms |
572 KB |
Output is correct |
23 |
Correct |
105 ms |
672 KB |
Output is correct |
24 |
Correct |
5 ms |
620 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 |
620 KB |
Output is correct |
28 |
Correct |
1 ms |
620 KB |
Output is correct |
29 |
Correct |
517 ms |
524 KB |
Output is correct |
30 |
Correct |
553 ms |
548 KB |
Output is correct |
31 |
Correct |
590 ms |
536 KB |
Output is correct |
32 |
Correct |
578 ms |
532 KB |
Output is correct |
33 |
Correct |
402 ms |
524 KB |
Output is correct |
34 |
Correct |
433 ms |
548 KB |
Output is correct |
35 |
Correct |
408 ms |
764 KB |
Output is correct |
36 |
Correct |
452 ms |
652 KB |
Output is correct |
37 |
Correct |
419 ms |
528 KB |
Output is correct |
38 |
Correct |
402 ms |
660 KB |
Output is correct |
39 |
Correct |
381 ms |
772 KB |
Output is correct |
40 |
Correct |
425 ms |
764 KB |
Output is correct |
41 |
Correct |
371 ms |
788 KB |
Output is correct |
42 |
Correct |
44 ms |
668 KB |
Output is correct |
43 |
Correct |
102 ms |
768 KB |
Output is correct |
44 |
Correct |
129 ms |
624 KB |
Output is correct |
45 |
Correct |
153 ms |
544 KB |
Output is correct |
46 |
Correct |
272 ms |
544 KB |
Output is correct |
47 |
Correct |
313 ms |
616 KB |
Output is correct |
48 |
Correct |
65 ms |
676 KB |
Output is correct |
49 |
Correct |
55 ms |
816 KB |
Output is correct |