#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
void dfs(int head, int par, vector<vector<int>> &tree, int &col, vector<int> &labels, int d){
if(!d){
labels[head] = col ++;
}
for(int i : tree[head]){
if(i != par){
dfs(i, head, tree, col, labels, d ^ 1);
}
}
if(d){
labels[head] = col++;
}
}
int find_next_station(int s, int t, vector<int> labels){
sort(labels.begin(), labels.end());
if(s < labels[0]){
if(t < s || t >= labels.back()){
return labels.back();
}
for(int i : labels){
if(i >= t){
return i;
}
}
}
else{
if(t > s || t <= labels[0]){
return labels[0];
}
reverse(labels.begin(), labels.end());
for(int i : labels){
if(i <= t){
return i;
}
}
}
}
vector<int> label(int N, int K, vector<int> U, vector<int> V){
vector<vector<int>> tree(N);
for(int i = 0; i < N-1; i ++){
tree[U[i]].push_back(V[i]);
tree[V[i]].push_back(U[i]);
}
vector<int> labels(N);
int col = 0;
dfs(0, -1, tree, col, labels, 0);
return labels;
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:40:1: warning: control reaches end of non-void function [-Wreturn-type]
40 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
400 ms |
672 KB |
Output is correct |
2 |
Correct |
305 ms |
636 KB |
Output is correct |
3 |
Correct |
607 ms |
504 KB |
Output is correct |
4 |
Correct |
520 ms |
500 KB |
Output is correct |
5 |
Correct |
562 ms |
636 KB |
Output is correct |
6 |
Correct |
259 ms |
544 KB |
Output is correct |
7 |
Correct |
324 ms |
548 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
3 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
396 ms |
544 KB |
Output is correct |
2 |
Correct |
436 ms |
508 KB |
Output is correct |
3 |
Correct |
693 ms |
416 KB |
Output is correct |
4 |
Correct |
470 ms |
508 KB |
Output is correct |
5 |
Correct |
532 ms |
500 KB |
Output is correct |
6 |
Correct |
429 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
405 ms |
672 KB |
Output is correct |
2 |
Correct |
390 ms |
636 KB |
Output is correct |
3 |
Correct |
709 ms |
504 KB |
Output is correct |
4 |
Correct |
572 ms |
416 KB |
Output is correct |
5 |
Correct |
429 ms |
528 KB |
Output is correct |
6 |
Correct |
411 ms |
760 KB |
Output is correct |
7 |
Correct |
343 ms |
632 KB |
Output is correct |
8 |
Correct |
1 ms |
500 KB |
Output is correct |
9 |
Correct |
3 ms |
488 KB |
Output is correct |
10 |
Correct |
0 ms |
492 KB |
Output is correct |
11 |
Correct |
414 ms |
420 KB |
Output is correct |
12 |
Correct |
352 ms |
708 KB |
Output is correct |
13 |
Correct |
379 ms |
716 KB |
Output is correct |
14 |
Correct |
366 ms |
544 KB |
Output is correct |
15 |
Correct |
37 ms |
492 KB |
Output is correct |
16 |
Correct |
57 ms |
568 KB |
Output is correct |
17 |
Correct |
64 ms |
576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
646 ms |
416 KB |
Output is correct |
2 |
Correct |
578 ms |
548 KB |
Output is correct |
3 |
Correct |
444 ms |
508 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
0 ms |
488 KB |
Output is correct |
7 |
Correct |
559 ms |
508 KB |
Output is correct |
8 |
Correct |
758 ms |
504 KB |
Output is correct |
9 |
Correct |
507 ms |
500 KB |
Output is correct |
10 |
Correct |
506 ms |
504 KB |
Output is correct |
11 |
Correct |
3 ms |
500 KB |
Output is correct |
12 |
Correct |
4 ms |
452 KB |
Output is correct |
13 |
Correct |
2 ms |
492 KB |
Output is correct |
14 |
Correct |
3 ms |
496 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
379 ms |
508 KB |
Output is correct |
17 |
Correct |
398 ms |
416 KB |
Output is correct |
18 |
Correct |
432 ms |
420 KB |
Output is correct |
19 |
Correct |
427 ms |
508 KB |
Output is correct |
20 |
Correct |
489 ms |
500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
368 ms |
632 KB |
Output is correct |
2 |
Correct |
400 ms |
632 KB |
Output is correct |
3 |
Correct |
706 ms |
508 KB |
Output is correct |
4 |
Correct |
459 ms |
420 KB |
Output is correct |
5 |
Correct |
409 ms |
420 KB |
Output is correct |
6 |
Correct |
381 ms |
628 KB |
Output is correct |
7 |
Correct |
382 ms |
508 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
3 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
500 KB |
Output is correct |
11 |
Correct |
325 ms |
508 KB |
Output is correct |
12 |
Correct |
433 ms |
544 KB |
Output is correct |
13 |
Correct |
662 ms |
420 KB |
Output is correct |
14 |
Correct |
558 ms |
508 KB |
Output is correct |
15 |
Correct |
503 ms |
420 KB |
Output is correct |
16 |
Correct |
333 ms |
548 KB |
Output is correct |
17 |
Correct |
484 ms |
416 KB |
Output is correct |
18 |
Correct |
364 ms |
732 KB |
Output is correct |
19 |
Correct |
282 ms |
708 KB |
Output is correct |
20 |
Correct |
298 ms |
544 KB |
Output is correct |
21 |
Correct |
57 ms |
492 KB |
Output is correct |
22 |
Correct |
52 ms |
556 KB |
Output is correct |
23 |
Correct |
75 ms |
640 KB |
Output is correct |
24 |
Correct |
5 ms |
492 KB |
Output is correct |
25 |
Correct |
4 ms |
492 KB |
Output is correct |
26 |
Correct |
3 ms |
500 KB |
Output is correct |
27 |
Correct |
3 ms |
492 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
391 ms |
416 KB |
Output is correct |
30 |
Correct |
430 ms |
420 KB |
Output is correct |
31 |
Correct |
463 ms |
416 KB |
Output is correct |
32 |
Correct |
371 ms |
420 KB |
Output is correct |
33 |
Correct |
360 ms |
504 KB |
Output is correct |
34 |
Correct |
272 ms |
548 KB |
Output is correct |
35 |
Correct |
343 ms |
688 KB |
Output is correct |
36 |
Correct |
364 ms |
632 KB |
Output is correct |
37 |
Correct |
400 ms |
624 KB |
Output is correct |
38 |
Correct |
313 ms |
692 KB |
Output is correct |
39 |
Correct |
354 ms |
580 KB |
Output is correct |
40 |
Correct |
322 ms |
632 KB |
Output is correct |
41 |
Correct |
363 ms |
632 KB |
Output is correct |
42 |
Correct |
58 ms |
548 KB |
Output is correct |
43 |
Correct |
67 ms |
548 KB |
Output is correct |
44 |
Correct |
89 ms |
544 KB |
Output is correct |
45 |
Correct |
151 ms |
548 KB |
Output is correct |
46 |
Correct |
260 ms |
544 KB |
Output is correct |
47 |
Correct |
227 ms |
508 KB |
Output is correct |
48 |
Correct |
44 ms |
684 KB |
Output is correct |
49 |
Correct |
42 ms |
676 KB |
Output is correct |