#include <bits/stdc++.h>
#define forint(i, N) for (int i = 0; i < (N); i++)
using namespace std;
vector<int> value;
vector<bool> visited;
int minval = 0;
void go(vector< vector<int> >& graph, int n, bool odd) {
visited[n] = true;
if (odd) {
for (auto& i : graph[n]) {
if (!visited[i]) {
go(graph, i, !odd);
}
}
value[n] = minval;
minval++;
}
else {
value[n] = minval;
minval++;
for (auto& i : graph[n]) {
if (!visited[i]) {
go(graph, i, !odd);
}
}
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector< vector<int> > graph(n);
minval = 0;
visited.clear();
visited.resize(n);
fill(visited.begin(), visited.end(), false);
value.clear();
value.resize(n);
fill(value.begin(), value.end(), -1);
forint(i, n - 1) {
graph[u[i]].push_back(v[i]);
graph[v[i]].push_back(u[i]);
}
go(graph, 0, true);
return value;
}
int find_next_station(int s, int t, vector<int> c) {
/*if (c.size() == 1) {
return c[0];
}
if (s > c[c.size() - 1] && t > s) {
return c[0];
}
if (s < c[0] && t < s) {
return c[c.size() - 1];
}
int left = 0;
int right = c.size() - 1;
while (left + 1 < right) {
if (t == c[left] || t == c[right]) {
return t;
}
int mid = (left + right) / 2;
if (t <= mid) {
right = mid;
}
else {
left = mid;
}
}
if (s < c[0]) {
return c[right];
}
return c[left];
*/
if (s < c[0]) {
if (t < s || t > c[c.size() - 1]) {
return c[c.size() - 1];
}
forint(i, c.size()) {
if (c[i] >= t) {
return c[i];
}
}
}
else {
if (t > s || t < c[0]) {
return c[0];
}
for (int i = c.size() - 1; i >= 0; i--) {
if (t >= c[i]) {
return c[i];
}
}
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:3:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
3 | #define forint(i, N) for (int i = 0; i < (N); i++)
| ^
stations.cpp:101:3: note: in expansion of macro 'forint'
101 | forint(i, c.size()) {
| ^~~~~~
stations.cpp:117:1: warning: control reaches end of non-void function [-Wreturn-type]
117 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
767 ms |
476 KB |
Output is correct |
2 |
Correct |
576 ms |
528 KB |
Output is correct |
3 |
Correct |
1059 ms |
400 KB |
Output is correct |
4 |
Correct |
783 ms |
468 KB |
Output is correct |
5 |
Correct |
726 ms |
484 KB |
Output is correct |
6 |
Correct |
451 ms |
480 KB |
Output is correct |
7 |
Correct |
547 ms |
528 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
604 ms |
616 KB |
Output is correct |
2 |
Correct |
731 ms |
528 KB |
Output is correct |
3 |
Correct |
1069 ms |
400 KB |
Output is correct |
4 |
Correct |
870 ms |
484 KB |
Output is correct |
5 |
Correct |
736 ms |
480 KB |
Output is correct |
6 |
Correct |
453 ms |
520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
759 ms |
616 KB |
Output is correct |
2 |
Correct |
619 ms |
592 KB |
Output is correct |
3 |
Correct |
1128 ms |
400 KB |
Output is correct |
4 |
Correct |
794 ms |
484 KB |
Output is correct |
5 |
Correct |
779 ms |
584 KB |
Output is correct |
6 |
Correct |
605 ms |
520 KB |
Output is correct |
7 |
Correct |
603 ms |
484 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
10 |
Correct |
3 ms |
540 KB |
Output is correct |
11 |
Correct |
642 ms |
488 KB |
Output is correct |
12 |
Correct |
560 ms |
616 KB |
Output is correct |
13 |
Correct |
641 ms |
688 KB |
Output is correct |
14 |
Correct |
578 ms |
488 KB |
Output is correct |
15 |
Correct |
57 ms |
400 KB |
Output is correct |
16 |
Correct |
83 ms |
528 KB |
Output is correct |
17 |
Correct |
152 ms |
528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
827 ms |
400 KB |
Output is correct |
2 |
Correct |
1015 ms |
488 KB |
Output is correct |
3 |
Correct |
711 ms |
484 KB |
Output is correct |
4 |
Correct |
3 ms |
464 KB |
Output is correct |
5 |
Correct |
4 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
464 KB |
Output is correct |
7 |
Correct |
856 ms |
484 KB |
Output is correct |
8 |
Correct |
1160 ms |
400 KB |
Output is correct |
9 |
Correct |
787 ms |
588 KB |
Output is correct |
10 |
Correct |
633 ms |
400 KB |
Output is correct |
11 |
Correct |
5 ms |
468 KB |
Output is correct |
12 |
Correct |
7 ms |
468 KB |
Output is correct |
13 |
Correct |
4 ms |
480 KB |
Output is correct |
14 |
Correct |
5 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
555 ms |
488 KB |
Output is correct |
17 |
Correct |
544 ms |
400 KB |
Output is correct |
18 |
Correct |
740 ms |
400 KB |
Output is correct |
19 |
Correct |
621 ms |
400 KB |
Output is correct |
20 |
Correct |
699 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
527 ms |
520 KB |
Output is correct |
2 |
Correct |
527 ms |
484 KB |
Output is correct |
3 |
Correct |
985 ms |
488 KB |
Output is correct |
4 |
Correct |
820 ms |
484 KB |
Output is correct |
5 |
Correct |
686 ms |
492 KB |
Output is correct |
6 |
Correct |
456 ms |
480 KB |
Output is correct |
7 |
Correct |
641 ms |
528 KB |
Output is correct |
8 |
Correct |
3 ms |
448 KB |
Output is correct |
9 |
Correct |
6 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
486 ms |
528 KB |
Output is correct |
12 |
Correct |
620 ms |
520 KB |
Output is correct |
13 |
Correct |
1067 ms |
400 KB |
Output is correct |
14 |
Correct |
833 ms |
500 KB |
Output is correct |
15 |
Correct |
654 ms |
472 KB |
Output is correct |
16 |
Correct |
600 ms |
528 KB |
Output is correct |
17 |
Correct |
618 ms |
528 KB |
Output is correct |
18 |
Correct |
586 ms |
648 KB |
Output is correct |
19 |
Correct |
525 ms |
488 KB |
Output is correct |
20 |
Correct |
504 ms |
496 KB |
Output is correct |
21 |
Correct |
61 ms |
420 KB |
Output is correct |
22 |
Correct |
81 ms |
484 KB |
Output is correct |
23 |
Correct |
105 ms |
528 KB |
Output is correct |
24 |
Correct |
6 ms |
468 KB |
Output is correct |
25 |
Correct |
8 ms |
468 KB |
Output is correct |
26 |
Correct |
4 ms |
468 KB |
Output is correct |
27 |
Correct |
4 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
476 KB |
Output is correct |
29 |
Correct |
613 ms |
404 KB |
Output is correct |
30 |
Correct |
641 ms |
492 KB |
Output is correct |
31 |
Correct |
606 ms |
528 KB |
Output is correct |
32 |
Correct |
591 ms |
400 KB |
Output is correct |
33 |
Correct |
513 ms |
488 KB |
Output is correct |
34 |
Correct |
402 ms |
488 KB |
Output is correct |
35 |
Correct |
503 ms |
604 KB |
Output is correct |
36 |
Correct |
440 ms |
476 KB |
Output is correct |
37 |
Correct |
489 ms |
652 KB |
Output is correct |
38 |
Correct |
576 ms |
608 KB |
Output is correct |
39 |
Correct |
563 ms |
640 KB |
Output is correct |
40 |
Correct |
489 ms |
732 KB |
Output is correct |
41 |
Correct |
582 ms |
700 KB |
Output is correct |
42 |
Correct |
70 ms |
508 KB |
Output is correct |
43 |
Correct |
151 ms |
648 KB |
Output is correct |
44 |
Correct |
185 ms |
528 KB |
Output is correct |
45 |
Correct |
184 ms |
528 KB |
Output is correct |
46 |
Correct |
384 ms |
560 KB |
Output is correct |
47 |
Correct |
346 ms |
484 KB |
Output is correct |
48 |
Correct |
70 ms |
528 KB |
Output is correct |
49 |
Correct |
61 ms |
528 KB |
Output is correct |