#include "stations.h"
#include <algorithm>
#include <vector>
using namespace std;
int dfs(
vector<vector<int>> const& graph,
vector<int>& label,
int const cur,
int start,
bool const left,
int const par
) {
int sz = 1;
if (left) {
label[cur] = start;
start++;
}
for (int const neigh : graph[cur]) {
if (neigh == par)
continue;
int const neigh_sz = dfs(graph, label, neigh, start, !left, cur);
sz += neigh_sz;
start += neigh_sz;
}
if (!left)
label[cur] = start;
return sz;
}
vector<int> label(int const n, int const k, vector<int> const u, vector<int> const v) {
vector<vector<int>> graph(n);
for (int i = 0; i < n - 1; i++) {
graph[u[i]].push_back(v[i]);
graph[v[i]].push_back(u[i]);
}
vector<int> label(n, -1);
dfs(graph, label, 0, 0, true, -1);
return label;
}
int find_next_station(int const s, int const t, vector<int> c) {
bool const left = s < c[0];
if (left) {
if (t < s)
return c.back();
for (int i = 0; i < c.size() - 1; i++)
if (c[i] >= t)
return c[i];
return c.back();
}
else {
reverse(c.begin(), c.end());
if (t > s)
return c.back();
for (int i = 0; i < c.size() - 1; i++)
if (c[i] <= t)
return c[i];
return c.back();
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:61:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for (int i = 0; i < c.size() - 1; i++)
| ~~^~~~~~~~~~~~~~
stations.cpp:73:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for (int i = 0; i < c.size() - 1; i++)
| ~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
492 ms |
648 KB |
Output is correct |
2 |
Correct |
422 ms |
616 KB |
Output is correct |
3 |
Correct |
874 ms |
484 KB |
Output is correct |
4 |
Correct |
691 ms |
492 KB |
Output is correct |
5 |
Correct |
560 ms |
496 KB |
Output is correct |
6 |
Correct |
364 ms |
616 KB |
Output is correct |
7 |
Correct |
510 ms |
544 KB |
Output is correct |
8 |
Correct |
1 ms |
488 KB |
Output is correct |
9 |
Correct |
4 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
445 ms |
544 KB |
Output is correct |
2 |
Correct |
549 ms |
604 KB |
Output is correct |
3 |
Correct |
942 ms |
472 KB |
Output is correct |
4 |
Correct |
626 ms |
544 KB |
Output is correct |
5 |
Correct |
681 ms |
420 KB |
Output is correct |
6 |
Correct |
467 ms |
496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
554 ms |
620 KB |
Output is correct |
2 |
Correct |
476 ms |
548 KB |
Output is correct |
3 |
Correct |
894 ms |
416 KB |
Output is correct |
4 |
Correct |
659 ms |
496 KB |
Output is correct |
5 |
Correct |
552 ms |
416 KB |
Output is correct |
6 |
Correct |
496 ms |
540 KB |
Output is correct |
7 |
Correct |
490 ms |
544 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
3 ms |
488 KB |
Output is correct |
10 |
Correct |
2 ms |
500 KB |
Output is correct |
11 |
Correct |
716 ms |
496 KB |
Output is correct |
12 |
Correct |
561 ms |
684 KB |
Output is correct |
13 |
Correct |
458 ms |
712 KB |
Output is correct |
14 |
Correct |
422 ms |
492 KB |
Output is correct |
15 |
Correct |
52 ms |
420 KB |
Output is correct |
16 |
Correct |
73 ms |
544 KB |
Output is correct |
17 |
Correct |
79 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
894 ms |
472 KB |
Output is correct |
2 |
Correct |
740 ms |
416 KB |
Output is correct |
3 |
Correct |
675 ms |
416 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
3 ms |
492 KB |
Output is correct |
6 |
Correct |
0 ms |
492 KB |
Output is correct |
7 |
Correct |
505 ms |
492 KB |
Output is correct |
8 |
Correct |
812 ms |
492 KB |
Output is correct |
9 |
Correct |
780 ms |
420 KB |
Output is correct |
10 |
Correct |
580 ms |
492 KB |
Output is correct |
11 |
Correct |
6 ms |
504 KB |
Output is correct |
12 |
Correct |
3 ms |
492 KB |
Output is correct |
13 |
Correct |
5 ms |
492 KB |
Output is correct |
14 |
Correct |
4 ms |
500 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
495 ms |
416 KB |
Output is correct |
17 |
Correct |
447 ms |
416 KB |
Output is correct |
18 |
Correct |
546 ms |
416 KB |
Output is correct |
19 |
Correct |
456 ms |
416 KB |
Output is correct |
20 |
Correct |
518 ms |
548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
471 ms |
620 KB |
Output is correct |
2 |
Correct |
442 ms |
544 KB |
Output is correct |
3 |
Correct |
830 ms |
420 KB |
Output is correct |
4 |
Correct |
647 ms |
416 KB |
Output is correct |
5 |
Correct |
617 ms |
492 KB |
Output is correct |
6 |
Correct |
481 ms |
620 KB |
Output is correct |
7 |
Correct |
471 ms |
544 KB |
Output is correct |
8 |
Correct |
1 ms |
500 KB |
Output is correct |
9 |
Correct |
4 ms |
500 KB |
Output is correct |
10 |
Correct |
1 ms |
500 KB |
Output is correct |
11 |
Correct |
432 ms |
492 KB |
Output is correct |
12 |
Correct |
530 ms |
492 KB |
Output is correct |
13 |
Correct |
796 ms |
420 KB |
Output is correct |
14 |
Correct |
653 ms |
492 KB |
Output is correct |
15 |
Correct |
585 ms |
416 KB |
Output is correct |
16 |
Correct |
439 ms |
612 KB |
Output is correct |
17 |
Correct |
616 ms |
416 KB |
Output is correct |
18 |
Correct |
431 ms |
664 KB |
Output is correct |
19 |
Correct |
413 ms |
688 KB |
Output is correct |
20 |
Correct |
457 ms |
500 KB |
Output is correct |
21 |
Correct |
49 ms |
492 KB |
Output is correct |
22 |
Correct |
55 ms |
548 KB |
Output is correct |
23 |
Correct |
88 ms |
544 KB |
Output is correct |
24 |
Correct |
6 ms |
504 KB |
Output is correct |
25 |
Correct |
4 ms |
492 KB |
Output is correct |
26 |
Correct |
4 ms |
492 KB |
Output is correct |
27 |
Correct |
2 ms |
492 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
439 ms |
488 KB |
Output is correct |
30 |
Correct |
388 ms |
420 KB |
Output is correct |
31 |
Correct |
415 ms |
496 KB |
Output is correct |
32 |
Correct |
568 ms |
416 KB |
Output is correct |
33 |
Correct |
441 ms |
416 KB |
Output is correct |
34 |
Correct |
273 ms |
548 KB |
Output is correct |
35 |
Correct |
361 ms |
676 KB |
Output is correct |
36 |
Correct |
386 ms |
612 KB |
Output is correct |
37 |
Correct |
423 ms |
496 KB |
Output is correct |
38 |
Correct |
487 ms |
664 KB |
Output is correct |
39 |
Correct |
446 ms |
592 KB |
Output is correct |
40 |
Correct |
412 ms |
664 KB |
Output is correct |
41 |
Correct |
387 ms |
920 KB |
Output is correct |
42 |
Correct |
73 ms |
548 KB |
Output is correct |
43 |
Correct |
115 ms |
544 KB |
Output is correct |
44 |
Correct |
114 ms |
548 KB |
Output is correct |
45 |
Correct |
140 ms |
572 KB |
Output is correct |
46 |
Correct |
254 ms |
544 KB |
Output is correct |
47 |
Correct |
237 ms |
488 KB |
Output is correct |
48 |
Correct |
53 ms |
572 KB |
Output is correct |
49 |
Correct |
54 ms |
488 KB |
Output is correct |