#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "stations.h"
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 gen(std :: chrono :: system_clock :: now().time_since_epoch().count());
const int N = 2e3 + 10;
int in[N], out[N], ti;
vector <int> g[N];
int depth[N];
void dfs(int u, int p, int d) {
in[u] = ++ti;
depth[u] = d;
for (auto v: g[u]) {
if (v == p) continue;
dfs(v, u, d ^ 1);
}
out[u] = ++ti;
}
int a[N];
vector <int> label(int n, int k, vector <int> U, vector <int> V) {
for (int i = 0; i < n - 1; ++i) {
g[U[i]].push_back(V[i]);
g[V[i]].push_back(U[i]);
}
dfs(0, -1, 0);
vector <int> ans, dta;
for (int i = 0; i < n; ++i)
a[i] = (!depth[i] ? out[i] : in[i]);
for (int i = 0; i < n; ++i) dta.push_back(a[i]);
sort(dta.begin(), dta.end());
for (int i = 0; i < n; ++i) ans.push_back(lower_bound(dta.begin(), dta.end(), a[i]) - dta.begin());
ti = 0;
for (int i = 0; i < n; ++i) in[i] = out[i] = depth[i] = 0, g[i].clear();
return ans;
}
int find_next_station(int s, int t, vector <int> g) {
if (g[0] > s) { // in
if (t < s) return g.back();
for (int i = 0; i < g.size(); ++i)
if (t <= g[i]) return g[i];
return g.back();
} else { // out
if (t > s) return g.front();
for (int i = g.size() - 1; i >= 0; --i)
if (t >= g[i]) return g[i];
return g.front();
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:54:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for (int i = 0; i < g.size(); ++i)
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
466 ms |
696 KB |
Output is correct |
2 |
Correct |
379 ms |
696 KB |
Output is correct |
3 |
Correct |
748 ms |
676 KB |
Output is correct |
4 |
Correct |
551 ms |
676 KB |
Output is correct |
5 |
Correct |
486 ms |
816 KB |
Output is correct |
6 |
Correct |
391 ms |
688 KB |
Output is correct |
7 |
Correct |
395 ms |
700 KB |
Output is correct |
8 |
Correct |
3 ms |
756 KB |
Output is correct |
9 |
Correct |
4 ms |
748 KB |
Output is correct |
10 |
Correct |
2 ms |
748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
400 ms |
672 KB |
Output is correct |
2 |
Correct |
473 ms |
676 KB |
Output is correct |
3 |
Correct |
766 ms |
688 KB |
Output is correct |
4 |
Correct |
574 ms |
692 KB |
Output is correct |
5 |
Correct |
495 ms |
676 KB |
Output is correct |
6 |
Correct |
387 ms |
688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
452 ms |
692 KB |
Output is correct |
2 |
Correct |
380 ms |
696 KB |
Output is correct |
3 |
Correct |
732 ms |
824 KB |
Output is correct |
4 |
Correct |
578 ms |
696 KB |
Output is correct |
5 |
Correct |
520 ms |
676 KB |
Output is correct |
6 |
Correct |
385 ms |
800 KB |
Output is correct |
7 |
Correct |
408 ms |
800 KB |
Output is correct |
8 |
Correct |
3 ms |
748 KB |
Output is correct |
9 |
Correct |
4 ms |
752 KB |
Output is correct |
10 |
Correct |
2 ms |
748 KB |
Output is correct |
11 |
Correct |
475 ms |
676 KB |
Output is correct |
12 |
Correct |
418 ms |
1064 KB |
Output is correct |
13 |
Correct |
410 ms |
812 KB |
Output is correct |
14 |
Correct |
376 ms |
800 KB |
Output is correct |
15 |
Correct |
47 ms |
672 KB |
Output is correct |
16 |
Correct |
54 ms |
676 KB |
Output is correct |
17 |
Correct |
93 ms |
732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
673 ms |
684 KB |
Output is correct |
2 |
Correct |
571 ms |
692 KB |
Output is correct |
3 |
Correct |
428 ms |
700 KB |
Output is correct |
4 |
Correct |
2 ms |
756 KB |
Output is correct |
5 |
Correct |
4 ms |
748 KB |
Output is correct |
6 |
Correct |
1 ms |
756 KB |
Output is correct |
7 |
Correct |
524 ms |
676 KB |
Output is correct |
8 |
Correct |
782 ms |
684 KB |
Output is correct |
9 |
Correct |
546 ms |
672 KB |
Output is correct |
10 |
Correct |
543 ms |
688 KB |
Output is correct |
11 |
Correct |
6 ms |
756 KB |
Output is correct |
12 |
Correct |
4 ms |
756 KB |
Output is correct |
13 |
Correct |
4 ms |
748 KB |
Output is correct |
14 |
Correct |
5 ms |
748 KB |
Output is correct |
15 |
Correct |
2 ms |
756 KB |
Output is correct |
16 |
Correct |
436 ms |
696 KB |
Output is correct |
17 |
Correct |
440 ms |
688 KB |
Output is correct |
18 |
Correct |
449 ms |
696 KB |
Output is correct |
19 |
Correct |
448 ms |
672 KB |
Output is correct |
20 |
Correct |
449 ms |
672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
457 ms |
692 KB |
Output is correct |
2 |
Correct |
415 ms |
672 KB |
Output is correct |
3 |
Correct |
737 ms |
676 KB |
Output is correct |
4 |
Correct |
549 ms |
692 KB |
Output is correct |
5 |
Correct |
499 ms |
676 KB |
Output is correct |
6 |
Correct |
387 ms |
692 KB |
Output is correct |
7 |
Correct |
413 ms |
672 KB |
Output is correct |
8 |
Correct |
3 ms |
756 KB |
Output is correct |
9 |
Correct |
4 ms |
756 KB |
Output is correct |
10 |
Correct |
2 ms |
748 KB |
Output is correct |
11 |
Correct |
406 ms |
688 KB |
Output is correct |
12 |
Correct |
481 ms |
696 KB |
Output is correct |
13 |
Correct |
732 ms |
696 KB |
Output is correct |
14 |
Correct |
622 ms |
672 KB |
Output is correct |
15 |
Correct |
551 ms |
692 KB |
Output is correct |
16 |
Correct |
383 ms |
672 KB |
Output is correct |
17 |
Correct |
527 ms |
672 KB |
Output is correct |
18 |
Correct |
429 ms |
800 KB |
Output is correct |
19 |
Correct |
380 ms |
812 KB |
Output is correct |
20 |
Correct |
339 ms |
676 KB |
Output is correct |
21 |
Correct |
42 ms |
748 KB |
Output is correct |
22 |
Correct |
49 ms |
664 KB |
Output is correct |
23 |
Correct |
96 ms |
676 KB |
Output is correct |
24 |
Correct |
5 ms |
756 KB |
Output is correct |
25 |
Correct |
5 ms |
748 KB |
Output is correct |
26 |
Correct |
3 ms |
748 KB |
Output is correct |
27 |
Correct |
4 ms |
748 KB |
Output is correct |
28 |
Correct |
2 ms |
756 KB |
Output is correct |
29 |
Correct |
406 ms |
692 KB |
Output is correct |
30 |
Correct |
422 ms |
688 KB |
Output is correct |
31 |
Correct |
459 ms |
676 KB |
Output is correct |
32 |
Correct |
454 ms |
672 KB |
Output is correct |
33 |
Correct |
442 ms |
688 KB |
Output is correct |
34 |
Correct |
272 ms |
808 KB |
Output is correct |
35 |
Correct |
395 ms |
916 KB |
Output is correct |
36 |
Correct |
397 ms |
692 KB |
Output is correct |
37 |
Correct |
392 ms |
804 KB |
Output is correct |
38 |
Correct |
337 ms |
804 KB |
Output is correct |
39 |
Correct |
375 ms |
820 KB |
Output is correct |
40 |
Correct |
393 ms |
832 KB |
Output is correct |
41 |
Correct |
381 ms |
836 KB |
Output is correct |
42 |
Correct |
57 ms |
728 KB |
Output is correct |
43 |
Correct |
91 ms |
672 KB |
Output is correct |
44 |
Correct |
114 ms |
676 KB |
Output is correct |
45 |
Correct |
141 ms |
696 KB |
Output is correct |
46 |
Correct |
286 ms |
592 KB |
Output is correct |
47 |
Correct |
245 ms |
676 KB |
Output is correct |
48 |
Correct |
50 ms |
868 KB |
Output is correct |
49 |
Correct |
59 ms |
852 KB |
Output is correct |