#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) x.begin(), x.end()
#define mp make_pair
#define mt make_tuple
#define x first
#define y second
#include "stations.h"
vector<int> label(int n, int k, vector<int> eu, vector<int> ev) {
assert(k >= n - 1);
vector<int> labels(n), order;
vector<vector<int>> g(n);
for (int i = 0; i < n - 1; ++i) {
g[ev[i]].push_back(eu[i]);
g[eu[i]].push_back(ev[i]);
}
function<void(int, int, bool)> dfs = [&](int v, int p, bool in) {
if (in) {
order.push_back(v);
}
for (int u : g[v]) {
if (u != p) {
dfs(u, v, !in);
}
}
if (!in) {
order.push_back(v);
}
};
dfs(0, 0, 1);
for (int i = 0; i < n; ++i) {
labels[order[i]] = i;
}
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
assert(is_sorted(all(c)));
assert(s != t);
if (c.size() == 1) {
return c[0];
}
if (c[0] < s) {
assert(c.back() < s);
if (t < c.front()) {
return c.front();
}
for (int i = 0; i + 1 < (int)c.size(); ++i) {
if (c[i] <= t && t < c[i + 1]) {
return c[i];
}
}
if (c.back() <= t && t < s) {
return c.back();
}
assert(t > s);
return c[0];
} else {
assert(c.front() > s);
if (t < s) {
return c.back();
}
for (int e : c) {
if (t <= e) {
return e;
}
}
return c.back();
}
}
#ifdef LC
#include "stub.cpp"
#endif
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
504 ms |
664 KB |
Output is correct |
2 |
Correct |
463 ms |
648 KB |
Output is correct |
3 |
Correct |
869 ms |
400 KB |
Output is correct |
4 |
Correct |
662 ms |
484 KB |
Output is correct |
5 |
Correct |
626 ms |
400 KB |
Output is correct |
6 |
Correct |
491 ms |
528 KB |
Output is correct |
7 |
Correct |
406 ms |
596 KB |
Output is correct |
8 |
Correct |
4 ms |
476 KB |
Output is correct |
9 |
Correct |
5 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
471 ms |
472 KB |
Output is correct |
2 |
Correct |
551 ms |
508 KB |
Output is correct |
3 |
Correct |
933 ms |
400 KB |
Output is correct |
4 |
Correct |
623 ms |
584 KB |
Output is correct |
5 |
Correct |
592 ms |
468 KB |
Output is correct |
6 |
Correct |
445 ms |
656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
546 ms |
604 KB |
Output is correct |
2 |
Correct |
488 ms |
612 KB |
Output is correct |
3 |
Correct |
725 ms |
544 KB |
Output is correct |
4 |
Correct |
806 ms |
404 KB |
Output is correct |
5 |
Correct |
599 ms |
488 KB |
Output is correct |
6 |
Correct |
502 ms |
612 KB |
Output is correct |
7 |
Correct |
448 ms |
616 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
610 ms |
488 KB |
Output is correct |
12 |
Correct |
475 ms |
732 KB |
Output is correct |
13 |
Correct |
463 ms |
692 KB |
Output is correct |
14 |
Correct |
454 ms |
520 KB |
Output is correct |
15 |
Correct |
51 ms |
468 KB |
Output is correct |
16 |
Correct |
61 ms |
548 KB |
Output is correct |
17 |
Correct |
112 ms |
576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
952 ms |
400 KB |
Output is correct |
2 |
Correct |
745 ms |
400 KB |
Output is correct |
3 |
Correct |
649 ms |
400 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
5 |
Correct |
6 ms |
448 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
7 |
Correct |
623 ms |
528 KB |
Output is correct |
8 |
Correct |
868 ms |
400 KB |
Output is correct |
9 |
Correct |
687 ms |
400 KB |
Output is correct |
10 |
Correct |
586 ms |
484 KB |
Output is correct |
11 |
Correct |
6 ms |
476 KB |
Output is correct |
12 |
Correct |
7 ms |
476 KB |
Output is correct |
13 |
Correct |
5 ms |
468 KB |
Output is correct |
14 |
Correct |
4 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
488 ms |
400 KB |
Output is correct |
17 |
Correct |
485 ms |
520 KB |
Output is correct |
18 |
Correct |
457 ms |
612 KB |
Output is correct |
19 |
Correct |
526 ms |
528 KB |
Output is correct |
20 |
Correct |
539 ms |
484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
572 ms |
656 KB |
Output is correct |
2 |
Correct |
483 ms |
616 KB |
Output is correct |
3 |
Correct |
915 ms |
400 KB |
Output is correct |
4 |
Correct |
641 ms |
468 KB |
Output is correct |
5 |
Correct |
623 ms |
528 KB |
Output is correct |
6 |
Correct |
465 ms |
656 KB |
Output is correct |
7 |
Correct |
494 ms |
520 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
459 ms |
528 KB |
Output is correct |
12 |
Correct |
541 ms |
476 KB |
Output is correct |
13 |
Correct |
879 ms |
400 KB |
Output is correct |
14 |
Correct |
697 ms |
472 KB |
Output is correct |
15 |
Correct |
589 ms |
400 KB |
Output is correct |
16 |
Correct |
437 ms |
528 KB |
Output is correct |
17 |
Correct |
569 ms |
400 KB |
Output is correct |
18 |
Correct |
491 ms |
696 KB |
Output is correct |
19 |
Correct |
474 ms |
608 KB |
Output is correct |
20 |
Correct |
456 ms |
656 KB |
Output is correct |
21 |
Correct |
57 ms |
428 KB |
Output is correct |
22 |
Correct |
73 ms |
528 KB |
Output is correct |
23 |
Correct |
98 ms |
556 KB |
Output is correct |
24 |
Correct |
7 ms |
420 KB |
Output is correct |
25 |
Correct |
6 ms |
472 KB |
Output is correct |
26 |
Correct |
4 ms |
476 KB |
Output is correct |
27 |
Correct |
4 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
472 KB |
Output is correct |
29 |
Correct |
503 ms |
528 KB |
Output is correct |
30 |
Correct |
485 ms |
400 KB |
Output is correct |
31 |
Correct |
543 ms |
492 KB |
Output is correct |
32 |
Correct |
532 ms |
400 KB |
Output is correct |
33 |
Correct |
531 ms |
400 KB |
Output is correct |
34 |
Correct |
309 ms |
620 KB |
Output is correct |
35 |
Correct |
431 ms |
684 KB |
Output is correct |
36 |
Correct |
484 ms |
520 KB |
Output is correct |
37 |
Correct |
460 ms |
528 KB |
Output is correct |
38 |
Correct |
498 ms |
692 KB |
Output is correct |
39 |
Correct |
489 ms |
568 KB |
Output is correct |
40 |
Correct |
487 ms |
596 KB |
Output is correct |
41 |
Correct |
450 ms |
544 KB |
Output is correct |
42 |
Correct |
71 ms |
528 KB |
Output is correct |
43 |
Correct |
99 ms |
496 KB |
Output is correct |
44 |
Correct |
135 ms |
624 KB |
Output is correct |
45 |
Correct |
175 ms |
528 KB |
Output is correct |
46 |
Correct |
311 ms |
528 KB |
Output is correct |
47 |
Correct |
334 ms |
616 KB |
Output is correct |
48 |
Correct |
65 ms |
544 KB |
Output is correct |
49 |
Correct |
66 ms |
636 KB |
Output is correct |