#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);
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:99:3: note: in expansion of macro 'forint'
99 | forint(i, c.size()) {
| ^~~~~~
stations.cpp:115:1: warning: control reaches end of non-void function [-Wreturn-type]
115 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
388 KB |
Invalid labels (values out of range). scenario=2, k=1000, vertex=0, label=1010 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
284 KB |
Invalid labels (values out of range). scenario=1, k=1000, vertex=0, label=1989 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
633 ms |
620 KB |
Output is correct |
2 |
Correct |
577 ms |
528 KB |
Output is correct |
3 |
Correct |
1020 ms |
400 KB |
Output is correct |
4 |
Correct |
763 ms |
492 KB |
Output is correct |
5 |
Correct |
800 ms |
540 KB |
Output is correct |
6 |
Correct |
581 ms |
528 KB |
Output is correct |
7 |
Correct |
552 ms |
520 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
695 ms |
480 KB |
Output is correct |
12 |
Correct |
652 ms |
600 KB |
Output is correct |
13 |
Correct |
487 ms |
612 KB |
Output is correct |
14 |
Correct |
532 ms |
528 KB |
Output is correct |
15 |
Correct |
53 ms |
468 KB |
Output is correct |
16 |
Correct |
67 ms |
548 KB |
Output is correct |
17 |
Correct |
147 ms |
532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
923 ms |
400 KB |
Output is correct |
2 |
Correct |
773 ms |
540 KB |
Output is correct |
3 |
Correct |
758 ms |
556 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
5 |
Correct |
5 ms |
476 KB |
Output is correct |
6 |
Correct |
4 ms |
468 KB |
Output is correct |
7 |
Correct |
755 ms |
528 KB |
Output is correct |
8 |
Correct |
1087 ms |
520 KB |
Output is correct |
9 |
Correct |
821 ms |
400 KB |
Output is correct |
10 |
Correct |
656 ms |
400 KB |
Output is correct |
11 |
Correct |
6 ms |
468 KB |
Output is correct |
12 |
Correct |
7 ms |
468 KB |
Output is correct |
13 |
Correct |
5 ms |
460 KB |
Output is correct |
14 |
Correct |
4 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
579 ms |
400 KB |
Output is correct |
17 |
Correct |
645 ms |
480 KB |
Output is correct |
18 |
Correct |
588 ms |
400 KB |
Output is correct |
19 |
Correct |
538 ms |
480 KB |
Output is correct |
20 |
Correct |
535 ms |
400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
680 ms |
528 KB |
Partially correct |
2 |
Partially correct |
561 ms |
656 KB |
Partially correct |
3 |
Correct |
948 ms |
480 KB |
Output is correct |
4 |
Correct |
704 ms |
400 KB |
Output is correct |
5 |
Correct |
753 ms |
528 KB |
Output is correct |
6 |
Partially correct |
584 ms |
612 KB |
Partially correct |
7 |
Correct |
520 ms |
480 KB |
Output is correct |
8 |
Correct |
3 ms |
476 KB |
Output is correct |
9 |
Correct |
5 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Partially correct |
530 ms |
552 KB |
Partially correct |
12 |
Partially correct |
566 ms |
488 KB |
Partially correct |
13 |
Correct |
974 ms |
400 KB |
Output is correct |
14 |
Correct |
675 ms |
484 KB |
Output is correct |
15 |
Correct |
668 ms |
400 KB |
Output is correct |
16 |
Correct |
464 ms |
488 KB |
Output is correct |
17 |
Correct |
712 ms |
404 KB |
Output is correct |
18 |
Partially correct |
617 ms |
596 KB |
Partially correct |
19 |
Partially correct |
645 ms |
592 KB |
Partially correct |
20 |
Correct |
510 ms |
488 KB |
Output is correct |
21 |
Correct |
59 ms |
432 KB |
Output is correct |
22 |
Partially correct |
94 ms |
548 KB |
Partially correct |
23 |
Partially correct |
111 ms |
528 KB |
Partially correct |
24 |
Correct |
6 ms |
468 KB |
Output is correct |
25 |
Correct |
5 ms |
468 KB |
Output is correct |
26 |
Correct |
6 ms |
476 KB |
Output is correct |
27 |
Correct |
5 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
516 KB |
Output is correct |
29 |
Correct |
676 ms |
488 KB |
Output is correct |
30 |
Correct |
683 ms |
400 KB |
Output is correct |
31 |
Correct |
527 ms |
400 KB |
Output is correct |
32 |
Correct |
682 ms |
400 KB |
Output is correct |
33 |
Correct |
596 ms |
528 KB |
Output is correct |
34 |
Partially correct |
402 ms |
496 KB |
Partially correct |
35 |
Partially correct |
631 ms |
708 KB |
Partially correct |
36 |
Partially correct |
531 ms |
596 KB |
Partially correct |
37 |
Partially correct |
541 ms |
652 KB |
Partially correct |
38 |
Partially correct |
510 ms |
564 KB |
Partially correct |
39 |
Partially correct |
577 ms |
644 KB |
Partially correct |
40 |
Partially correct |
541 ms |
608 KB |
Partially correct |
41 |
Partially correct |
449 ms |
640 KB |
Partially correct |
42 |
Partially correct |
80 ms |
576 KB |
Partially correct |
43 |
Partially correct |
104 ms |
556 KB |
Partially correct |
44 |
Partially correct |
175 ms |
528 KB |
Partially correct |
45 |
Partially correct |
182 ms |
560 KB |
Partially correct |
46 |
Partially correct |
309 ms |
484 KB |
Partially correct |
47 |
Partially correct |
326 ms |
548 KB |
Partially correct |
48 |
Partially correct |
84 ms |
632 KB |
Partially correct |
49 |
Partially correct |
69 ms |
528 KB |
Partially correct |