#include <bits/stdc++.h>
#include "stations.h"
using namespace std;
int _labels[1010];
vector<int> adj[1010];
int N, K, timer = 0;
void dfs(int a, int p, int lv){
if(!lv) _labels[a] = timer++;
for(auto x : adj[a]){
if(x == p) continue;
dfs(x, a, 1 - lv);
}
if(lv) _labels[a] = timer++;
}
vector<int> label(int _N, int _K, vector<int> U, vector<int> V) {
N = _N; K = _K; timer = 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, 0, 0);
vector<int> res;
for(int i = 0; i < N; i++) res.push_back(_labels[i]);
for(int i = 0; i < N; i++) adj[i].clear();
return res;
}
int find_next_station(int S, int T, vector<int> C) {
if(C.size() == 1) return C[0];
if(C[0] > S){
int st = S;
for(int i = 0; i < C.size() - 1; i++){
if(st < T && T <= C[i]) return C[i];
st = C[i];
}
return C[C.size() - 1];
}
else{
for(int i = 1; i < C.size() - 1; i++){
if(C[i] <= T && T < C[i + 1]) return C[i];
}
if(C[C.size() - 1] <= T && T < S) return C[C.size() - 1];
return C[0];
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:35:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(int i = 0; i < C.size() - 1; i++){
| ~~^~~~~~~~~~~~~~
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 = 1; i < C.size() - 1; i++){
| ~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
544 ms |
544 KB |
Output is correct |
2 |
Correct |
442 ms |
520 KB |
Output is correct |
3 |
Correct |
805 ms |
416 KB |
Output is correct |
4 |
Correct |
703 ms |
416 KB |
Output is correct |
5 |
Correct |
515 ms |
532 KB |
Output is correct |
6 |
Correct |
441 ms |
524 KB |
Output is correct |
7 |
Correct |
450 ms |
564 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
3 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
403 ms |
532 KB |
Output is correct |
2 |
Correct |
506 ms |
524 KB |
Output is correct |
3 |
Correct |
903 ms |
416 KB |
Output is correct |
4 |
Correct |
602 ms |
416 KB |
Output is correct |
5 |
Correct |
575 ms |
416 KB |
Output is correct |
6 |
Correct |
472 ms |
536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
450 ms |
652 KB |
Output is correct |
2 |
Correct |
576 ms |
528 KB |
Output is correct |
3 |
Correct |
730 ms |
516 KB |
Output is correct |
4 |
Correct |
802 ms |
416 KB |
Output is correct |
5 |
Correct |
708 ms |
416 KB |
Output is correct |
6 |
Correct |
509 ms |
532 KB |
Output is correct |
7 |
Correct |
392 ms |
544 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
4 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
744 ms |
416 KB |
Output is correct |
12 |
Correct |
443 ms |
644 KB |
Output is correct |
13 |
Correct |
511 ms |
660 KB |
Output is correct |
14 |
Correct |
528 ms |
528 KB |
Output is correct |
15 |
Correct |
58 ms |
468 KB |
Output is correct |
16 |
Correct |
70 ms |
692 KB |
Output is correct |
17 |
Correct |
122 ms |
676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
794 ms |
416 KB |
Output is correct |
2 |
Correct |
637 ms |
524 KB |
Output is correct |
3 |
Correct |
563 ms |
420 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
4 ms |
492 KB |
Output is correct |
6 |
Correct |
0 ms |
492 KB |
Output is correct |
7 |
Correct |
562 ms |
420 KB |
Output is correct |
8 |
Correct |
860 ms |
536 KB |
Output is correct |
9 |
Correct |
615 ms |
656 KB |
Output is correct |
10 |
Correct |
513 ms |
524 KB |
Output is correct |
11 |
Correct |
5 ms |
488 KB |
Output is correct |
12 |
Correct |
3 ms |
492 KB |
Output is correct |
13 |
Correct |
3 ms |
496 KB |
Output is correct |
14 |
Correct |
4 ms |
500 KB |
Output is correct |
15 |
Correct |
1 ms |
500 KB |
Output is correct |
16 |
Correct |
508 ms |
420 KB |
Output is correct |
17 |
Correct |
498 ms |
488 KB |
Output is correct |
18 |
Correct |
461 ms |
536 KB |
Output is correct |
19 |
Correct |
476 ms |
536 KB |
Output is correct |
20 |
Correct |
476 ms |
532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
582 ms |
548 KB |
Output is correct |
2 |
Correct |
341 ms |
532 KB |
Output is correct |
3 |
Correct |
636 ms |
656 KB |
Output is correct |
4 |
Correct |
648 ms |
420 KB |
Output is correct |
5 |
Correct |
520 ms |
416 KB |
Output is correct |
6 |
Correct |
315 ms |
548 KB |
Output is correct |
7 |
Correct |
460 ms |
544 KB |
Output is correct |
8 |
Correct |
3 ms |
500 KB |
Output is correct |
9 |
Correct |
3 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
492 KB |
Output is correct |
11 |
Correct |
437 ms |
532 KB |
Output is correct |
12 |
Correct |
493 ms |
532 KB |
Output is correct |
13 |
Correct |
819 ms |
536 KB |
Output is correct |
14 |
Correct |
570 ms |
508 KB |
Output is correct |
15 |
Correct |
556 ms |
416 KB |
Output is correct |
16 |
Correct |
419 ms |
548 KB |
Output is correct |
17 |
Correct |
568 ms |
724 KB |
Output is correct |
18 |
Correct |
412 ms |
652 KB |
Output is correct |
19 |
Correct |
465 ms |
748 KB |
Output is correct |
20 |
Correct |
464 ms |
512 KB |
Output is correct |
21 |
Correct |
46 ms |
544 KB |
Output is correct |
22 |
Correct |
46 ms |
544 KB |
Output is correct |
23 |
Correct |
105 ms |
672 KB |
Output is correct |
24 |
Correct |
4 ms |
492 KB |
Output is correct |
25 |
Correct |
2 ms |
492 KB |
Output is correct |
26 |
Correct |
3 ms |
492 KB |
Output is correct |
27 |
Correct |
4 ms |
492 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
456 ms |
416 KB |
Output is correct |
30 |
Correct |
518 ms |
520 KB |
Output is correct |
31 |
Correct |
487 ms |
416 KB |
Output is correct |
32 |
Correct |
458 ms |
420 KB |
Output is correct |
33 |
Correct |
412 ms |
416 KB |
Output is correct |
34 |
Correct |
301 ms |
548 KB |
Output is correct |
35 |
Correct |
380 ms |
660 KB |
Output is correct |
36 |
Correct |
456 ms |
636 KB |
Output is correct |
37 |
Correct |
450 ms |
656 KB |
Output is correct |
38 |
Correct |
473 ms |
768 KB |
Output is correct |
39 |
Correct |
408 ms |
664 KB |
Output is correct |
40 |
Correct |
405 ms |
640 KB |
Output is correct |
41 |
Correct |
380 ms |
836 KB |
Output is correct |
42 |
Correct |
65 ms |
572 KB |
Output is correct |
43 |
Correct |
90 ms |
548 KB |
Output is correct |
44 |
Correct |
114 ms |
544 KB |
Output is correct |
45 |
Correct |
173 ms |
544 KB |
Output is correct |
46 |
Correct |
265 ms |
548 KB |
Output is correct |
47 |
Correct |
270 ms |
544 KB |
Output is correct |
48 |
Correct |
54 ms |
728 KB |
Output is correct |
49 |
Correct |
45 ms |
764 KB |
Output is correct |