#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
template<typename T>
using Prior = priority_queue<T>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back
const int maxn = 1000 + 5;
vector<int> adj[maxn], lab, sz;
int tok = 0;
void dfs(int now, int lst, int lay = 1) {
if (lay) lab[now] = tok++;
sz[now] = 1;
for (auto x : adj[now]) {
if (x != lst) dfs(x, now, lay^1), sz[now] += sz[x];
}
if (!lay) lab[now] = tok++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
for (int i = 0; i < maxn; ++i) adj[i].clear();
lab.resize(n), sz.resize(n);
tok = 0;
for (int i = 0; i < n-1; ++i) {
adj[u[i]].eb(v[i]), adj[v[i]].eb(u[i]);
}
dfs(0, -1);
// cout << "lab : ";
// for (int i = 0; i < n; ++i) cout << lab[i] << " \n"[i == n-1];
return lab;
}
int find_next_station(int s, int t, vector<int> c) {
if (c.front() > s) {
/// pre ///
if (s > t) return c.back();
for (int i = 0; i < c.size()-1; ++i) {
if (c[i] >= t) return c[i];
}
return c.back();
}
if (c.front() < s) {
/// post ///
if (s < t) return c.front();
for (int i = c.size()-1; i >= 1; --i) {
if (c[i] <= t) return c[i];
}
return c.front();
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:52:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for (int i = 0; i < c.size()-1; ++i) {
| ~~^~~~~~~~~~~~
stations.cpp:67:1: warning: control reaches end of non-void function [-Wreturn-type]
67 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
593 ms |
1008 KB |
Output is correct |
2 |
Correct |
466 ms |
1008 KB |
Output is correct |
3 |
Correct |
1003 ms |
768 KB |
Output is correct |
4 |
Correct |
686 ms |
768 KB |
Output is correct |
5 |
Correct |
615 ms |
880 KB |
Output is correct |
6 |
Correct |
513 ms |
1024 KB |
Output is correct |
7 |
Correct |
541 ms |
1280 KB |
Output is correct |
8 |
Correct |
2 ms |
892 KB |
Output is correct |
9 |
Correct |
4 ms |
768 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
541 ms |
768 KB |
Output is correct |
2 |
Correct |
561 ms |
832 KB |
Output is correct |
3 |
Correct |
950 ms |
768 KB |
Output is correct |
4 |
Correct |
652 ms |
768 KB |
Output is correct |
5 |
Correct |
649 ms |
1008 KB |
Output is correct |
6 |
Correct |
520 ms |
824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
628 ms |
1024 KB |
Output is correct |
2 |
Correct |
513 ms |
1024 KB |
Output is correct |
3 |
Correct |
1033 ms |
768 KB |
Output is correct |
4 |
Correct |
656 ms |
872 KB |
Output is correct |
5 |
Correct |
620 ms |
1048 KB |
Output is correct |
6 |
Correct |
469 ms |
1024 KB |
Output is correct |
7 |
Correct |
477 ms |
896 KB |
Output is correct |
8 |
Correct |
3 ms |
896 KB |
Output is correct |
9 |
Correct |
4 ms |
888 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
11 |
Correct |
721 ms |
876 KB |
Output is correct |
12 |
Correct |
613 ms |
1116 KB |
Output is correct |
13 |
Correct |
541 ms |
1008 KB |
Output is correct |
14 |
Correct |
546 ms |
768 KB |
Output is correct |
15 |
Correct |
49 ms |
768 KB |
Output is correct |
16 |
Correct |
78 ms |
832 KB |
Output is correct |
17 |
Correct |
148 ms |
804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1091 ms |
768 KB |
Output is correct |
2 |
Correct |
750 ms |
768 KB |
Output is correct |
3 |
Correct |
710 ms |
1024 KB |
Output is correct |
4 |
Correct |
3 ms |
888 KB |
Output is correct |
5 |
Correct |
5 ms |
768 KB |
Output is correct |
6 |
Correct |
2 ms |
888 KB |
Output is correct |
7 |
Correct |
707 ms |
1040 KB |
Output is correct |
8 |
Correct |
1087 ms |
768 KB |
Output is correct |
9 |
Correct |
830 ms |
768 KB |
Output is correct |
10 |
Correct |
567 ms |
768 KB |
Output is correct |
11 |
Correct |
5 ms |
768 KB |
Output is correct |
12 |
Correct |
6 ms |
768 KB |
Output is correct |
13 |
Correct |
4 ms |
768 KB |
Output is correct |
14 |
Correct |
4 ms |
888 KB |
Output is correct |
15 |
Correct |
2 ms |
768 KB |
Output is correct |
16 |
Correct |
590 ms |
1008 KB |
Output is correct |
17 |
Correct |
611 ms |
768 KB |
Output is correct |
18 |
Correct |
554 ms |
1036 KB |
Output is correct |
19 |
Correct |
585 ms |
1036 KB |
Output is correct |
20 |
Correct |
514 ms |
876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
578 ms |
1024 KB |
Output is correct |
2 |
Correct |
454 ms |
1024 KB |
Output is correct |
3 |
Correct |
989 ms |
768 KB |
Output is correct |
4 |
Correct |
726 ms |
768 KB |
Output is correct |
5 |
Correct |
729 ms |
880 KB |
Output is correct |
6 |
Correct |
549 ms |
1008 KB |
Output is correct |
7 |
Correct |
584 ms |
800 KB |
Output is correct |
8 |
Correct |
3 ms |
884 KB |
Output is correct |
9 |
Correct |
4 ms |
892 KB |
Output is correct |
10 |
Correct |
1 ms |
888 KB |
Output is correct |
11 |
Correct |
552 ms |
768 KB |
Output is correct |
12 |
Correct |
650 ms |
948 KB |
Output is correct |
13 |
Correct |
1154 ms |
896 KB |
Output is correct |
14 |
Correct |
587 ms |
672 KB |
Output is correct |
15 |
Correct |
658 ms |
880 KB |
Output is correct |
16 |
Correct |
487 ms |
824 KB |
Output is correct |
17 |
Correct |
705 ms |
880 KB |
Output is correct |
18 |
Correct |
561 ms |
1024 KB |
Output is correct |
19 |
Correct |
519 ms |
1096 KB |
Output is correct |
20 |
Correct |
475 ms |
824 KB |
Output is correct |
21 |
Correct |
62 ms |
868 KB |
Output is correct |
22 |
Correct |
72 ms |
836 KB |
Output is correct |
23 |
Correct |
115 ms |
812 KB |
Output is correct |
24 |
Correct |
7 ms |
1024 KB |
Output is correct |
25 |
Correct |
6 ms |
768 KB |
Output is correct |
26 |
Correct |
5 ms |
876 KB |
Output is correct |
27 |
Correct |
3 ms |
1024 KB |
Output is correct |
28 |
Correct |
2 ms |
884 KB |
Output is correct |
29 |
Correct |
540 ms |
768 KB |
Output is correct |
30 |
Correct |
636 ms |
880 KB |
Output is correct |
31 |
Correct |
526 ms |
768 KB |
Output is correct |
32 |
Correct |
651 ms |
768 KB |
Output is correct |
33 |
Correct |
643 ms |
880 KB |
Output is correct |
34 |
Correct |
365 ms |
1280 KB |
Output is correct |
35 |
Correct |
468 ms |
1024 KB |
Output is correct |
36 |
Correct |
551 ms |
1024 KB |
Output is correct |
37 |
Correct |
539 ms |
888 KB |
Output is correct |
38 |
Correct |
557 ms |
1024 KB |
Output is correct |
39 |
Correct |
442 ms |
1024 KB |
Output is correct |
40 |
Correct |
538 ms |
1140 KB |
Output is correct |
41 |
Correct |
489 ms |
896 KB |
Output is correct |
42 |
Correct |
63 ms |
828 KB |
Output is correct |
43 |
Correct |
148 ms |
816 KB |
Output is correct |
44 |
Correct |
143 ms |
792 KB |
Output is correct |
45 |
Correct |
209 ms |
920 KB |
Output is correct |
46 |
Correct |
365 ms |
808 KB |
Output is correct |
47 |
Correct |
337 ms |
776 KB |
Output is correct |
48 |
Correct |
71 ms |
784 KB |
Output is correct |
49 |
Correct |
82 ms |
1024 KB |
Output is correct |