#include "stations.h"
#include <vector>
#include <iostream>
using namespace std;
#define ll long long
#define add push_back
#define len(a) ((int)(a).size())
vector<int> g[1005];
vector<int> labels;
int timer = 0;
void dfs(int v, int p, bool m){
if(m == 0) labels[v] = timer++;
for(int i = 0; i < len(g[v]); i++){
int to = g[v][i];
if(to == p) continue;
dfs(to, v, !m);
}
if(m == 1) labels[v] = timer++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
labels.resize(n);
timer = 0;
for(int i = 0; i < n; i++) {
g[i].clear();
}
for(int i = 0; i < len(u); i++){
g[u[i]].add(v[i]);
g[v[i]].add(u[i]);
}
dfs(0, 0, false);
// for(int i = 0; i < n; i++){
// cout << labels[i] << " ";
// }
// cout << endl;
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
// cout << s << " " << t << ": " << "\n";
// for(int i = 0; i < len(c); i++){
// cout << c[i] << " ";
// }
if(len(c) == 1){
return c[0];
}
int l, r;
if(s < c[0]){
l = s;
r = (s == 0 ? c[len(c) - 1] : c[len(c) - 2]);
if(!(l <= t && t <= r)){
// cout << len(c) - 1 << " ___ " << c[len(c) - 1] << endl;
return c[len(c) - 1];
}
int ind = (s == 0 ? len(c) - 1 : len(c) - 2);
while(ind >= 0 && t <= c[ind]){ ind--; }
// cout << ind + 1 << " __ " << c[ind + 1] << endl;
return c[++ind];
}
r = s;
l = c[1];
if(!(l <= t && t <= r)){
// cout << 0 << " " << c[0] << endl;
return c[0];
}
int ind = 1;
while(ind < len(c) && t >= c[ind]) { ind++; }
// cout << ind - 1 << " _ " << c[ind - 1] << endl;
return c[--ind];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
523 ms |
544 KB |
Output is correct |
2 |
Correct |
420 ms |
536 KB |
Output is correct |
3 |
Correct |
884 ms |
528 KB |
Output is correct |
4 |
Correct |
620 ms |
416 KB |
Output is correct |
5 |
Correct |
486 ms |
524 KB |
Output is correct |
6 |
Correct |
451 ms |
660 KB |
Output is correct |
7 |
Correct |
398 ms |
544 KB |
Output is correct |
8 |
Correct |
1 ms |
500 KB |
Output is correct |
9 |
Correct |
4 ms |
496 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
398 ms |
528 KB |
Output is correct |
2 |
Correct |
496 ms |
548 KB |
Output is correct |
3 |
Correct |
868 ms |
528 KB |
Output is correct |
4 |
Correct |
677 ms |
416 KB |
Output is correct |
5 |
Correct |
630 ms |
420 KB |
Output is correct |
6 |
Correct |
450 ms |
532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
520 ms |
672 KB |
Output is correct |
2 |
Correct |
403 ms |
652 KB |
Output is correct |
3 |
Correct |
787 ms |
420 KB |
Output is correct |
4 |
Correct |
610 ms |
564 KB |
Output is correct |
5 |
Correct |
616 ms |
528 KB |
Output is correct |
6 |
Correct |
404 ms |
656 KB |
Output is correct |
7 |
Correct |
437 ms |
548 KB |
Output is correct |
8 |
Correct |
2 ms |
488 KB |
Output is correct |
9 |
Correct |
3 ms |
560 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
564 ms |
416 KB |
Output is correct |
12 |
Correct |
413 ms |
672 KB |
Output is correct |
13 |
Correct |
508 ms |
756 KB |
Output is correct |
14 |
Correct |
458 ms |
548 KB |
Output is correct |
15 |
Correct |
51 ms |
420 KB |
Output is correct |
16 |
Correct |
54 ms |
576 KB |
Output is correct |
17 |
Correct |
102 ms |
544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
819 ms |
528 KB |
Output is correct |
2 |
Correct |
653 ms |
416 KB |
Output is correct |
3 |
Correct |
488 ms |
524 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
3 ms |
492 KB |
Output is correct |
6 |
Correct |
0 ms |
500 KB |
Output is correct |
7 |
Correct |
546 ms |
588 KB |
Output is correct |
8 |
Correct |
873 ms |
440 KB |
Output is correct |
9 |
Correct |
568 ms |
420 KB |
Output is correct |
10 |
Correct |
600 ms |
528 KB |
Output is correct |
11 |
Correct |
5 ms |
496 KB |
Output is correct |
12 |
Correct |
6 ms |
492 KB |
Output is correct |
13 |
Correct |
5 ms |
500 KB |
Output is correct |
14 |
Correct |
3 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
500 KB |
Output is correct |
16 |
Correct |
468 ms |
536 KB |
Output is correct |
17 |
Correct |
351 ms |
528 KB |
Output is correct |
18 |
Correct |
508 ms |
420 KB |
Output is correct |
19 |
Correct |
478 ms |
420 KB |
Output is correct |
20 |
Correct |
495 ms |
416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
501 ms |
688 KB |
Output is correct |
2 |
Correct |
447 ms |
676 KB |
Output is correct |
3 |
Correct |
907 ms |
420 KB |
Output is correct |
4 |
Correct |
616 ms |
532 KB |
Output is correct |
5 |
Correct |
570 ms |
528 KB |
Output is correct |
6 |
Correct |
476 ms |
656 KB |
Output is correct |
7 |
Correct |
449 ms |
540 KB |
Output is correct |
8 |
Correct |
3 ms |
504 KB |
Output is correct |
9 |
Correct |
5 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
492 KB |
Output is correct |
11 |
Correct |
503 ms |
524 KB |
Output is correct |
12 |
Correct |
543 ms |
544 KB |
Output is correct |
13 |
Correct |
836 ms |
416 KB |
Output is correct |
14 |
Correct |
659 ms |
420 KB |
Output is correct |
15 |
Correct |
606 ms |
416 KB |
Output is correct |
16 |
Correct |
449 ms |
524 KB |
Output is correct |
17 |
Correct |
599 ms |
544 KB |
Output is correct |
18 |
Correct |
493 ms |
652 KB |
Output is correct |
19 |
Correct |
434 ms |
760 KB |
Output is correct |
20 |
Correct |
482 ms |
532 KB |
Output is correct |
21 |
Correct |
48 ms |
444 KB |
Output is correct |
22 |
Correct |
67 ms |
572 KB |
Output is correct |
23 |
Correct |
93 ms |
672 KB |
Output is correct |
24 |
Correct |
6 ms |
500 KB |
Output is correct |
25 |
Correct |
5 ms |
492 KB |
Output is correct |
26 |
Correct |
4 ms |
492 KB |
Output is correct |
27 |
Correct |
3 ms |
492 KB |
Output is correct |
28 |
Correct |
2 ms |
500 KB |
Output is correct |
29 |
Correct |
527 ms |
420 KB |
Output is correct |
30 |
Correct |
549 ms |
544 KB |
Output is correct |
31 |
Correct |
436 ms |
420 KB |
Output is correct |
32 |
Correct |
568 ms |
416 KB |
Output is correct |
33 |
Correct |
412 ms |
420 KB |
Output is correct |
34 |
Correct |
310 ms |
632 KB |
Output is correct |
35 |
Correct |
419 ms |
748 KB |
Output is correct |
36 |
Correct |
544 ms |
740 KB |
Output is correct |
37 |
Correct |
637 ms |
636 KB |
Output is correct |
38 |
Correct |
407 ms |
624 KB |
Output is correct |
39 |
Correct |
476 ms |
728 KB |
Output is correct |
40 |
Correct |
540 ms |
640 KB |
Output is correct |
41 |
Correct |
464 ms |
712 KB |
Output is correct |
42 |
Correct |
62 ms |
664 KB |
Output is correct |
43 |
Correct |
110 ms |
548 KB |
Output is correct |
44 |
Correct |
127 ms |
544 KB |
Output is correct |
45 |
Correct |
181 ms |
588 KB |
Output is correct |
46 |
Correct |
278 ms |
544 KB |
Output is correct |
47 |
Correct |
281 ms |
548 KB |
Output is correct |
48 |
Correct |
40 ms |
652 KB |
Output is correct |
49 |
Correct |
56 ms |
696 KB |
Output is correct |