#include "stations.h"
#include <vector>
#include <algorithm>
std::vector<std::vector<int>> adj;
void dfs(int u, int p, int k, std::vector<int> &labels, int &r) {
if (k) labels[u] = r++;
for (int v : adj[u]) if (v != p) dfs(v, u, !k, labels, r);
if (!k) labels[u] = r++;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
adj.assign(n, std::vector<int>(0));
for (int i = 0; i < (int) u.size(); ++i) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
std::vector<int> labels(n);
int r = 0;
dfs(0, -1, 1, labels, r);
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
std::sort(c.begin(), c.end());
if (s == 0) {
return *std::lower_bound(c.begin(), c.end(), t);
} else if ((int) c.size() == 1) {
return c[0];
} else if (s < c[0]) {
if (t < s || c.back() < t) return c.back();
else return *std::lower_bound(c.begin(), c.end(), t);
} else {
if (t <= c[0] || s < t) return c[0];
return *prev(std::upper_bound(c.begin(), c.end(), t));
}
return c[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
556 ms |
736 KB |
Output is correct |
2 |
Correct |
544 ms |
604 KB |
Output is correct |
3 |
Correct |
1261 ms |
520 KB |
Output is correct |
4 |
Correct |
755 ms |
476 KB |
Output is correct |
5 |
Correct |
740 ms |
472 KB |
Output is correct |
6 |
Correct |
597 ms |
528 KB |
Output is correct |
7 |
Correct |
641 ms |
472 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
6 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
510 ms |
604 KB |
Output is correct |
2 |
Correct |
598 ms |
624 KB |
Output is correct |
3 |
Correct |
1089 ms |
456 KB |
Output is correct |
4 |
Correct |
666 ms |
528 KB |
Output is correct |
5 |
Correct |
681 ms |
520 KB |
Output is correct |
6 |
Correct |
539 ms |
528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
678 ms |
700 KB |
Output is correct |
2 |
Correct |
642 ms |
520 KB |
Output is correct |
3 |
Correct |
871 ms |
400 KB |
Output is correct |
4 |
Correct |
851 ms |
400 KB |
Output is correct |
5 |
Correct |
774 ms |
400 KB |
Output is correct |
6 |
Correct |
567 ms |
600 KB |
Output is correct |
7 |
Correct |
548 ms |
604 KB |
Output is correct |
8 |
Correct |
5 ms |
448 KB |
Output is correct |
9 |
Correct |
6 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
600 ms |
400 KB |
Output is correct |
12 |
Correct |
689 ms |
668 KB |
Output is correct |
13 |
Correct |
565 ms |
668 KB |
Output is correct |
14 |
Correct |
655 ms |
476 KB |
Output is correct |
15 |
Correct |
66 ms |
524 KB |
Output is correct |
16 |
Correct |
106 ms |
528 KB |
Output is correct |
17 |
Correct |
120 ms |
528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1039 ms |
472 KB |
Output is correct |
2 |
Correct |
899 ms |
528 KB |
Output is correct |
3 |
Correct |
740 ms |
476 KB |
Output is correct |
4 |
Correct |
3 ms |
460 KB |
Output is correct |
5 |
Correct |
5 ms |
472 KB |
Output is correct |
6 |
Correct |
2 ms |
524 KB |
Output is correct |
7 |
Correct |
751 ms |
484 KB |
Output is correct |
8 |
Correct |
1057 ms |
476 KB |
Output is correct |
9 |
Correct |
732 ms |
400 KB |
Output is correct |
10 |
Correct |
683 ms |
548 KB |
Output is correct |
11 |
Correct |
10 ms |
468 KB |
Output is correct |
12 |
Correct |
8 ms |
516 KB |
Output is correct |
13 |
Correct |
6 ms |
524 KB |
Output is correct |
14 |
Correct |
6 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
645 ms |
476 KB |
Output is correct |
17 |
Correct |
666 ms |
400 KB |
Output is correct |
18 |
Correct |
646 ms |
400 KB |
Output is correct |
19 |
Correct |
603 ms |
476 KB |
Output is correct |
20 |
Correct |
650 ms |
476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
586 ms |
652 KB |
Output is correct |
2 |
Correct |
629 ms |
760 KB |
Output is correct |
3 |
Correct |
961 ms |
456 KB |
Output is correct |
4 |
Correct |
895 ms |
464 KB |
Output is correct |
5 |
Correct |
746 ms |
456 KB |
Output is correct |
6 |
Correct |
561 ms |
600 KB |
Output is correct |
7 |
Correct |
569 ms |
476 KB |
Output is correct |
8 |
Correct |
3 ms |
584 KB |
Output is correct |
9 |
Correct |
5 ms |
400 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
618 ms |
580 KB |
Output is correct |
12 |
Correct |
630 ms |
548 KB |
Output is correct |
13 |
Correct |
1065 ms |
480 KB |
Output is correct |
14 |
Correct |
832 ms |
400 KB |
Output is correct |
15 |
Correct |
712 ms |
400 KB |
Output is correct |
16 |
Correct |
609 ms |
476 KB |
Output is correct |
17 |
Correct |
764 ms |
472 KB |
Output is correct |
18 |
Correct |
640 ms |
576 KB |
Output is correct |
19 |
Correct |
542 ms |
592 KB |
Output is correct |
20 |
Correct |
465 ms |
472 KB |
Output is correct |
21 |
Correct |
60 ms |
568 KB |
Output is correct |
22 |
Correct |
77 ms |
528 KB |
Output is correct |
23 |
Correct |
137 ms |
552 KB |
Output is correct |
24 |
Correct |
9 ms |
476 KB |
Output is correct |
25 |
Correct |
6 ms |
568 KB |
Output is correct |
26 |
Correct |
6 ms |
468 KB |
Output is correct |
27 |
Correct |
7 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
464 KB |
Output is correct |
29 |
Correct |
647 ms |
476 KB |
Output is correct |
30 |
Correct |
651 ms |
400 KB |
Output is correct |
31 |
Correct |
581 ms |
472 KB |
Output is correct |
32 |
Correct |
659 ms |
472 KB |
Output is correct |
33 |
Correct |
635 ms |
416 KB |
Output is correct |
34 |
Correct |
440 ms |
596 KB |
Output is correct |
35 |
Correct |
531 ms |
532 KB |
Output is correct |
36 |
Correct |
604 ms |
604 KB |
Output is correct |
37 |
Correct |
635 ms |
660 KB |
Output is correct |
38 |
Correct |
546 ms |
704 KB |
Output is correct |
39 |
Correct |
564 ms |
608 KB |
Output is correct |
40 |
Correct |
578 ms |
684 KB |
Output is correct |
41 |
Correct |
578 ms |
544 KB |
Output is correct |
42 |
Correct |
61 ms |
528 KB |
Output is correct |
43 |
Correct |
163 ms |
600 KB |
Output is correct |
44 |
Correct |
140 ms |
528 KB |
Output is correct |
45 |
Correct |
206 ms |
608 KB |
Output is correct |
46 |
Correct |
331 ms |
528 KB |
Output is correct |
47 |
Correct |
389 ms |
604 KB |
Output is correct |
48 |
Correct |
79 ms |
584 KB |
Output is correct |
49 |
Correct |
71 ms |
624 KB |
Output is correct |