//#pragma GCC target("avx2")
//#pragma GCC optimization("O3")
//#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << " "
#define nl cout << "\n"
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MAXN = 1e3;
vector<int> g[MAXN];
int timer, tin[MAXN], tou[MAXN];
void dfs(int v, int d, vector<int>& labels){
tin[v] = timer++;
for(int u : g[v]){
g[u].erase(find(all(g[u]), v));
dfs(u, d ^ 1, labels);
}
tou[v] = timer++;
if(d & 1) labels[v] = tou[v];
else labels[v] = tin[v];
}
vector<int> label(int N, int K, vector<int> u, vector<int> v){
rep(i, 0, N){
g[i].clear();
}
auto add_edge = [&](int a, int b){
g[a].pb(b);
g[b].pb(a);
};
rep(i, 0, N - 1){
add_edge(u[i], v[i]);
}
vector<int> labels(N);
timer = 0;
dfs(0, 0, labels);
vector<pii> b(N);
rep(i, 0, N){
b[i] = {labels[i], i};
}
sort(all(b));
rep(i, 0, N){
labels[b[i].ss] = i;
}
return labels;
}
int find_next_station(int s, int t, vector<int> c){
bool tin = true, tou = true;
for(int x : c){
tin &= (s < x);
tou &= (s > x);
}
if(tin){
sort(all(c));
rep(i, 0, SZ(c) - 1){
if(s <= t && t <= c[i]){
return c[i];
}
}
return c.back();
} else if(tou){
sort(all(c), greater<int>());
rep(i, 0, SZ(c) - 1){
if(c[i] <= t && t <= s){
return c[i];
}
}
return c.back();
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:83:1: warning: control reaches end of non-void function [-Wreturn-type]
83 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
654 ms |
992 KB |
Output is correct |
2 |
Correct |
452 ms |
1040 KB |
Output is correct |
3 |
Correct |
1075 ms |
736 KB |
Output is correct |
4 |
Correct |
763 ms |
864 KB |
Output is correct |
5 |
Correct |
674 ms |
992 KB |
Output is correct |
6 |
Correct |
444 ms |
1012 KB |
Output is correct |
7 |
Correct |
470 ms |
992 KB |
Output is correct |
8 |
Correct |
3 ms |
864 KB |
Output is correct |
9 |
Correct |
5 ms |
864 KB |
Output is correct |
10 |
Correct |
2 ms |
940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
491 ms |
864 KB |
Output is correct |
2 |
Correct |
580 ms |
1020 KB |
Output is correct |
3 |
Correct |
931 ms |
940 KB |
Output is correct |
4 |
Correct |
688 ms |
736 KB |
Output is correct |
5 |
Correct |
611 ms |
940 KB |
Output is correct |
6 |
Correct |
628 ms |
884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
738 ms |
992 KB |
Output is correct |
2 |
Correct |
447 ms |
992 KB |
Output is correct |
3 |
Correct |
1125 ms |
864 KB |
Output is correct |
4 |
Correct |
949 ms |
992 KB |
Output is correct |
5 |
Correct |
863 ms |
864 KB |
Output is correct |
6 |
Correct |
417 ms |
992 KB |
Output is correct |
7 |
Correct |
539 ms |
992 KB |
Output is correct |
8 |
Correct |
3 ms |
948 KB |
Output is correct |
9 |
Correct |
7 ms |
864 KB |
Output is correct |
10 |
Correct |
2 ms |
736 KB |
Output is correct |
11 |
Correct |
592 ms |
864 KB |
Output is correct |
12 |
Correct |
485 ms |
904 KB |
Output is correct |
13 |
Correct |
477 ms |
1176 KB |
Output is correct |
14 |
Correct |
525 ms |
864 KB |
Output is correct |
15 |
Correct |
56 ms |
932 KB |
Output is correct |
16 |
Correct |
70 ms |
736 KB |
Output is correct |
17 |
Correct |
119 ms |
884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
889 ms |
864 KB |
Output is correct |
2 |
Correct |
706 ms |
872 KB |
Output is correct |
3 |
Correct |
617 ms |
736 KB |
Output is correct |
4 |
Correct |
3 ms |
736 KB |
Output is correct |
5 |
Correct |
5 ms |
736 KB |
Output is correct |
6 |
Correct |
2 ms |
864 KB |
Output is correct |
7 |
Correct |
675 ms |
940 KB |
Output is correct |
8 |
Correct |
868 ms |
1020 KB |
Output is correct |
9 |
Correct |
682 ms |
864 KB |
Output is correct |
10 |
Correct |
680 ms |
864 KB |
Output is correct |
11 |
Correct |
7 ms |
736 KB |
Output is correct |
12 |
Correct |
7 ms |
940 KB |
Output is correct |
13 |
Correct |
6 ms |
832 KB |
Output is correct |
14 |
Correct |
5 ms |
864 KB |
Output is correct |
15 |
Correct |
2 ms |
948 KB |
Output is correct |
16 |
Correct |
545 ms |
864 KB |
Output is correct |
17 |
Correct |
572 ms |
736 KB |
Output is correct |
18 |
Correct |
629 ms |
1032 KB |
Output is correct |
19 |
Correct |
642 ms |
872 KB |
Output is correct |
20 |
Correct |
607 ms |
864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
596 ms |
1004 KB |
Output is correct |
2 |
Correct |
520 ms |
992 KB |
Output is correct |
3 |
Correct |
975 ms |
1236 KB |
Output is correct |
4 |
Correct |
907 ms |
736 KB |
Output is correct |
5 |
Correct |
763 ms |
736 KB |
Output is correct |
6 |
Correct |
489 ms |
1084 KB |
Output is correct |
7 |
Correct |
532 ms |
864 KB |
Output is correct |
8 |
Correct |
3 ms |
736 KB |
Output is correct |
9 |
Correct |
5 ms |
736 KB |
Output is correct |
10 |
Correct |
2 ms |
940 KB |
Output is correct |
11 |
Correct |
478 ms |
736 KB |
Output is correct |
12 |
Correct |
536 ms |
1108 KB |
Output is correct |
13 |
Correct |
1018 ms |
864 KB |
Output is correct |
14 |
Correct |
737 ms |
1012 KB |
Output is correct |
15 |
Correct |
704 ms |
940 KB |
Output is correct |
16 |
Correct |
489 ms |
864 KB |
Output is correct |
17 |
Correct |
669 ms |
864 KB |
Output is correct |
18 |
Correct |
481 ms |
1284 KB |
Output is correct |
19 |
Correct |
503 ms |
944 KB |
Output is correct |
20 |
Correct |
469 ms |
864 KB |
Output is correct |
21 |
Correct |
75 ms |
864 KB |
Output is correct |
22 |
Correct |
92 ms |
1024 KB |
Output is correct |
23 |
Correct |
116 ms |
864 KB |
Output is correct |
24 |
Correct |
6 ms |
864 KB |
Output is correct |
25 |
Correct |
4 ms |
864 KB |
Output is correct |
26 |
Correct |
5 ms |
736 KB |
Output is correct |
27 |
Correct |
5 ms |
1068 KB |
Output is correct |
28 |
Correct |
2 ms |
940 KB |
Output is correct |
29 |
Correct |
575 ms |
940 KB |
Output is correct |
30 |
Correct |
527 ms |
992 KB |
Output is correct |
31 |
Correct |
610 ms |
1108 KB |
Output is correct |
32 |
Correct |
675 ms |
864 KB |
Output is correct |
33 |
Correct |
568 ms |
1108 KB |
Output is correct |
34 |
Correct |
393 ms |
992 KB |
Output is correct |
35 |
Correct |
531 ms |
1308 KB |
Output is correct |
36 |
Correct |
548 ms |
1052 KB |
Output is correct |
37 |
Correct |
512 ms |
1084 KB |
Output is correct |
38 |
Correct |
471 ms |
944 KB |
Output is correct |
39 |
Correct |
506 ms |
1120 KB |
Output is correct |
40 |
Correct |
455 ms |
992 KB |
Output is correct |
41 |
Correct |
458 ms |
1088 KB |
Output is correct |
42 |
Correct |
81 ms |
884 KB |
Output is correct |
43 |
Correct |
102 ms |
736 KB |
Output is correct |
44 |
Correct |
171 ms |
864 KB |
Output is correct |
45 |
Correct |
177 ms |
992 KB |
Output is correct |
46 |
Correct |
306 ms |
868 KB |
Output is correct |
47 |
Correct |
330 ms |
1220 KB |
Output is correct |
48 |
Correct |
72 ms |
1076 KB |
Output is correct |
49 |
Correct |
61 ms |
992 KB |
Output is correct |