#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
#define sep ' '
const int MAXN = 1010;
int timer , ans[MAXN];
vector<int> adj[MAXN];
void DFS(int v , int p = -1 , int h = 0){
if(h % 2 == 0) ans[v] = timer++;
for(int u : adj[v]){
if(u == p) continue;
DFS(u , v , h + 1);
}
if(h % 2 == 1) ans[v] = timer++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<int> labels(n , 0); timer = 0;
for (int i = 0; i < n; i++) {
adj[i].clear(); ans[i] = 0;
}
for(int i = 0 ; i < n - 1 ; i++){
adj[v[i]].push_back(u[i]);
adj[u[i]].push_back(v[i]);
}
DFS(0);
for(int i = 0 ; i < n ; i++){
labels[i] = ans[i];
// cout << i << sep << ans[i] << endl;
}
return labels;
}
int SolveSt(int s , int t , vector<int> c){
// cout << "solveSt " << s << sep << t << sep << c.size() << endl;
int prv = s;
for(int u : c){
if(prv < t && t <= u) return u;
prv = u;
}
return c.back();
}
int SolveFn(int s , int t , vector<int> c){
// cout << "SolveFn " << s << sep << t << sep << c.size() << endl;
int prv = s;
reverse(c.begin() , c.end());
for(int u : c){
// cout << u << endl;
if(u <= t && t < prv) return u;
prv = u;
}
return c.back();
}
int find_next_station(int s, int t, vector<int> c) {
// cout << "query " << s << sep << t << endl;
if(s < c[0]) return SolveSt(s , t , c);
if(s > c[0]) return SolveFn(s , t , c);
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:63:1: warning: control reaches end of non-void function [-Wreturn-type]
63 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
902 ms |
640 KB |
Output is correct |
2 |
Correct |
582 ms |
840 KB |
Output is correct |
3 |
Correct |
1273 ms |
400 KB |
Output is correct |
4 |
Correct |
789 ms |
500 KB |
Output is correct |
5 |
Correct |
996 ms |
400 KB |
Output is correct |
6 |
Correct |
734 ms |
528 KB |
Output is correct |
7 |
Correct |
533 ms |
524 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
6 ms |
400 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
738 ms |
504 KB |
Output is correct |
2 |
Correct |
669 ms |
528 KB |
Output is correct |
3 |
Correct |
1253 ms |
400 KB |
Output is correct |
4 |
Correct |
837 ms |
516 KB |
Output is correct |
5 |
Correct |
826 ms |
508 KB |
Output is correct |
6 |
Correct |
700 ms |
528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
578 ms |
528 KB |
Output is correct |
2 |
Correct |
507 ms |
512 KB |
Output is correct |
3 |
Correct |
1442 ms |
400 KB |
Output is correct |
4 |
Correct |
732 ms |
400 KB |
Output is correct |
5 |
Correct |
1031 ms |
512 KB |
Output is correct |
6 |
Correct |
601 ms |
512 KB |
Output is correct |
7 |
Correct |
694 ms |
512 KB |
Output is correct |
8 |
Correct |
3 ms |
420 KB |
Output is correct |
9 |
Correct |
6 ms |
472 KB |
Output is correct |
10 |
Correct |
2 ms |
476 KB |
Output is correct |
11 |
Correct |
719 ms |
400 KB |
Output is correct |
12 |
Correct |
851 ms |
732 KB |
Output is correct |
13 |
Correct |
544 ms |
756 KB |
Output is correct |
14 |
Correct |
685 ms |
500 KB |
Output is correct |
15 |
Correct |
62 ms |
576 KB |
Output is correct |
16 |
Correct |
97 ms |
532 KB |
Output is correct |
17 |
Correct |
170 ms |
660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1428 ms |
400 KB |
Output is correct |
2 |
Correct |
807 ms |
516 KB |
Output is correct |
3 |
Correct |
822 ms |
436 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
5 |
Correct |
7 ms |
476 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
841 ms |
516 KB |
Output is correct |
8 |
Correct |
1371 ms |
400 KB |
Output is correct |
9 |
Correct |
705 ms |
588 KB |
Output is correct |
10 |
Correct |
802 ms |
520 KB |
Output is correct |
11 |
Correct |
6 ms |
672 KB |
Output is correct |
12 |
Correct |
9 ms |
432 KB |
Output is correct |
13 |
Correct |
8 ms |
468 KB |
Output is correct |
14 |
Correct |
6 ms |
480 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
578 ms |
456 KB |
Output is correct |
17 |
Correct |
770 ms |
400 KB |
Output is correct |
18 |
Correct |
577 ms |
640 KB |
Output is correct |
19 |
Correct |
620 ms |
508 KB |
Output is correct |
20 |
Correct |
678 ms |
400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
679 ms |
528 KB |
Output is correct |
2 |
Correct |
507 ms |
500 KB |
Output is correct |
3 |
Correct |
900 ms |
400 KB |
Output is correct |
4 |
Correct |
742 ms |
400 KB |
Output is correct |
5 |
Correct |
599 ms |
512 KB |
Output is correct |
6 |
Correct |
545 ms |
656 KB |
Output is correct |
7 |
Correct |
520 ms |
516 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 |
11 |
Correct |
484 ms |
516 KB |
Output is correct |
12 |
Correct |
708 ms |
528 KB |
Output is correct |
13 |
Correct |
933 ms |
400 KB |
Output is correct |
14 |
Correct |
739 ms |
400 KB |
Output is correct |
15 |
Correct |
679 ms |
548 KB |
Output is correct |
16 |
Correct |
477 ms |
528 KB |
Output is correct |
17 |
Correct |
698 ms |
636 KB |
Output is correct |
18 |
Correct |
603 ms |
636 KB |
Output is correct |
19 |
Correct |
572 ms |
876 KB |
Output is correct |
20 |
Correct |
555 ms |
508 KB |
Output is correct |
21 |
Correct |
52 ms |
528 KB |
Output is correct |
22 |
Correct |
67 ms |
528 KB |
Output is correct |
23 |
Correct |
131 ms |
756 KB |
Output is correct |
24 |
Correct |
6 ms |
468 KB |
Output is correct |
25 |
Correct |
7 ms |
468 KB |
Output is correct |
26 |
Correct |
6 ms |
476 KB |
Output is correct |
27 |
Correct |
4 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
589 ms |
508 KB |
Output is correct |
30 |
Correct |
659 ms |
552 KB |
Output is correct |
31 |
Correct |
582 ms |
400 KB |
Output is correct |
32 |
Correct |
585 ms |
512 KB |
Output is correct |
33 |
Correct |
468 ms |
508 KB |
Output is correct |
34 |
Correct |
446 ms |
504 KB |
Output is correct |
35 |
Correct |
476 ms |
752 KB |
Output is correct |
36 |
Correct |
554 ms |
720 KB |
Output is correct |
37 |
Correct |
489 ms |
644 KB |
Output is correct |
38 |
Correct |
642 ms |
656 KB |
Output is correct |
39 |
Correct |
517 ms |
712 KB |
Output is correct |
40 |
Correct |
519 ms |
616 KB |
Output is correct |
41 |
Correct |
574 ms |
620 KB |
Output is correct |
42 |
Correct |
91 ms |
712 KB |
Output is correct |
43 |
Correct |
100 ms |
716 KB |
Output is correct |
44 |
Correct |
189 ms |
528 KB |
Output is correct |
45 |
Correct |
147 ms |
528 KB |
Output is correct |
46 |
Correct |
382 ms |
528 KB |
Output is correct |
47 |
Correct |
370 ms |
528 KB |
Output is correct |
48 |
Correct |
70 ms |
656 KB |
Output is correct |
49 |
Correct |
82 ms |
740 KB |
Output is correct |