#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<vector<int>> g(n);
for (int i = 0; i + 1 < n; i++) {
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
vector<int> tin(n), tout(n), lab(n);
int T = 0;
function<void(int, int, int)> Dfs = [&](int v, int pv, int d) {
if (d % 2 == 0) {
lab[v] = ++T;
}
for (int u : g[v]) {
if (u == pv) {
continue;
}
Dfs(u, v, d ^ 1);
}
if (d % 2 == 1) {
lab[v] = ++T;
}
};
Dfs(0, 0, 0);
return lab;
}
int find_next_station(int s, int t, vector<int> c) {
int n = (int) c.size();
if (n == 1) {
return c[0];
}
for (int i = 0; i < n; i++) {
if (c[i] == t) {
return c[i];
}
}
for (int i = 0; i < n; i++) {
assert(s != c[i]);
}
if (s < c[0]) {
if (t >= s && t <= c[0]) {
return c[0];
}
for (int i = 1; i + 1 < n; i++) {
if (t > c[i - 1] && t <= c[i]) {
return c[i];
}
}
return c[n - 1];
} else {
assert(s > c[n - 1]);
if (t >= c[n - 1] && t <= s) {
return c[n - 1];
}
for (int i = n - 2; i > 0; i--) {
if (t >= c[i] && t < c[i + 1]) {
return c[i];
}
}
return c[0];
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
422 ms |
624 KB |
Output is correct |
2 |
Correct |
406 ms |
676 KB |
Output is correct |
3 |
Correct |
762 ms |
568 KB |
Output is correct |
4 |
Correct |
587 ms |
544 KB |
Output is correct |
5 |
Correct |
514 ms |
504 KB |
Output is correct |
6 |
Correct |
384 ms |
632 KB |
Output is correct |
7 |
Correct |
379 ms |
544 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
6 ms |
500 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
410 ms |
496 KB |
Output is correct |
2 |
Correct |
483 ms |
632 KB |
Output is correct |
3 |
Correct |
763 ms |
416 KB |
Output is correct |
4 |
Correct |
585 ms |
500 KB |
Output is correct |
5 |
Correct |
548 ms |
504 KB |
Output is correct |
6 |
Correct |
396 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
485 ms |
636 KB |
Output is correct |
2 |
Correct |
392 ms |
672 KB |
Output is correct |
3 |
Correct |
796 ms |
480 KB |
Output is correct |
4 |
Correct |
619 ms |
508 KB |
Output is correct |
5 |
Correct |
529 ms |
420 KB |
Output is correct |
6 |
Correct |
430 ms |
628 KB |
Output is correct |
7 |
Correct |
426 ms |
636 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
7 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
497 ms |
416 KB |
Output is correct |
12 |
Correct |
390 ms |
708 KB |
Output is correct |
13 |
Correct |
402 ms |
784 KB |
Output is correct |
14 |
Correct |
401 ms |
544 KB |
Output is correct |
15 |
Correct |
45 ms |
444 KB |
Output is correct |
16 |
Correct |
48 ms |
588 KB |
Output is correct |
17 |
Correct |
103 ms |
500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
758 ms |
416 KB |
Output is correct |
2 |
Correct |
599 ms |
504 KB |
Output is correct |
3 |
Correct |
436 ms |
508 KB |
Output is correct |
4 |
Correct |
3 ms |
496 KB |
Output is correct |
5 |
Correct |
4 ms |
492 KB |
Output is correct |
6 |
Correct |
0 ms |
500 KB |
Output is correct |
7 |
Correct |
498 ms |
416 KB |
Output is correct |
8 |
Correct |
754 ms |
420 KB |
Output is correct |
9 |
Correct |
535 ms |
504 KB |
Output is correct |
10 |
Correct |
514 ms |
420 KB |
Output is correct |
11 |
Correct |
5 ms |
492 KB |
Output is correct |
12 |
Correct |
5 ms |
492 KB |
Output is correct |
13 |
Correct |
4 ms |
500 KB |
Output is correct |
14 |
Correct |
4 ms |
500 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
445 ms |
420 KB |
Output is correct |
17 |
Correct |
420 ms |
504 KB |
Output is correct |
18 |
Correct |
381 ms |
484 KB |
Output is correct |
19 |
Correct |
422 ms |
504 KB |
Output is correct |
20 |
Correct |
446 ms |
420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
413 ms |
656 KB |
Output is correct |
2 |
Correct |
374 ms |
676 KB |
Output is correct |
3 |
Correct |
741 ms |
420 KB |
Output is correct |
4 |
Correct |
559 ms |
416 KB |
Output is correct |
5 |
Correct |
496 ms |
420 KB |
Output is correct |
6 |
Correct |
353 ms |
696 KB |
Output is correct |
7 |
Correct |
392 ms |
548 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
500 KB |
Output is correct |
11 |
Correct |
368 ms |
504 KB |
Output is correct |
12 |
Correct |
473 ms |
548 KB |
Output is correct |
13 |
Correct |
652 ms |
416 KB |
Output is correct |
14 |
Correct |
480 ms |
420 KB |
Output is correct |
15 |
Correct |
500 ms |
508 KB |
Output is correct |
16 |
Correct |
397 ms |
488 KB |
Output is correct |
17 |
Correct |
543 ms |
416 KB |
Output is correct |
18 |
Correct |
370 ms |
544 KB |
Output is correct |
19 |
Correct |
379 ms |
712 KB |
Output is correct |
20 |
Correct |
411 ms |
496 KB |
Output is correct |
21 |
Correct |
53 ms |
468 KB |
Output is correct |
22 |
Correct |
59 ms |
500 KB |
Output is correct |
23 |
Correct |
93 ms |
544 KB |
Output is correct |
24 |
Correct |
5 ms |
492 KB |
Output is correct |
25 |
Correct |
6 ms |
492 KB |
Output is correct |
26 |
Correct |
3 ms |
492 KB |
Output is correct |
27 |
Correct |
4 ms |
500 KB |
Output is correct |
28 |
Correct |
2 ms |
500 KB |
Output is correct |
29 |
Correct |
429 ms |
508 KB |
Output is correct |
30 |
Correct |
409 ms |
500 KB |
Output is correct |
31 |
Correct |
441 ms |
420 KB |
Output is correct |
32 |
Correct |
364 ms |
504 KB |
Output is correct |
33 |
Correct |
463 ms |
420 KB |
Output is correct |
34 |
Correct |
246 ms |
676 KB |
Output is correct |
35 |
Correct |
350 ms |
752 KB |
Output is correct |
36 |
Correct |
369 ms |
784 KB |
Output is correct |
37 |
Correct |
386 ms |
660 KB |
Output is correct |
38 |
Correct |
377 ms |
632 KB |
Output is correct |
39 |
Correct |
387 ms |
576 KB |
Output is correct |
40 |
Correct |
403 ms |
600 KB |
Output is correct |
41 |
Correct |
390 ms |
508 KB |
Output is correct |
42 |
Correct |
56 ms |
572 KB |
Output is correct |
43 |
Correct |
87 ms |
600 KB |
Output is correct |
44 |
Correct |
120 ms |
500 KB |
Output is correct |
45 |
Correct |
151 ms |
504 KB |
Output is correct |
46 |
Correct |
251 ms |
544 KB |
Output is correct |
47 |
Correct |
244 ms |
548 KB |
Output is correct |
48 |
Correct |
57 ms |
600 KB |
Output is correct |
49 |
Correct |
61 ms |
504 KB |
Output is correct |