#include <bits/stdc++.h>
/// #include "stations.h"
/// #pragma GCC optimize ("Ofast")
/// #pragma GCC target ("avx2")
/// #pragma GCC optimize("unroll-loops")
using namespace std;
int timer;
vector<int> key, adj[1001];
void dfs(int v, int p, int dep) {
if(dep == 0) key[v] = timer++;
for(auto u : adj[v]) {
if(u == p) continue;
dfs(u, v, 1 - dep);
}
if(dep == 1) key[v] = timer++;
}
vector<int> label(int N, int K, vector<int> U, vector<int> V) {
timer = 0; key.assign(N, 0);
for(int l = 0; l < N; l++) adj[l].clear();
for(int l = 0; l < N - 1; l++) {
int X = U[l], Y = V[l];
adj[X].push_back(Y), adj[Y].push_back(X);
}
dfs(0, 0, 0);
return key;
}
int find_next_station(int S, int T, vector<int> C) {
if(C.size() == 1) return C[0];
bool tin = 1; int N = C.size(); T *= 2;
for(auto u : C) tin &= (u > S);
if(tin) {
int I = 2 * S, O;
if(I == 0) O = 2 * C[N - 1] + 1;
else O = 2 * C[N - 2] + 1;
if(T < I || T > O) return C[N - 1];
if(I != 0) N--;
vector<pair<int, int>> A(N);
for(int l = 1; l < N; l++) {
A[l].second = C[l] * 2;
A[l].first = C[l - 1] * 2 + 1;
}
A[0] = {S * 2 + 1, 2 * C[0]};
for(int l = 0; l < N; l++) {
I = A[l].first, O = A[l].second;
if(T >= I && T <= O)
return C[l];
}
}
else {
int I = 2 * C[1] - 1, O = 2 * S;
if(T < I || T > O) return C[0];
vector<pair<int, int>> A(N);
for(int l = 1; l < N - 1; l++) {
A[l].first = C[l] * 2;
A[l].second = C[l + 1] * 2 - 1;
}
A[N - 1] = {C[N - 1] * 2, O - 1};
for(int l = 1; l < N; l++) {
I = A[l].first, O = A[l].second;
if(T >= I && T <= O)
return C[l];
}
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:68:9: warning: control reaches end of non-void function [-Wreturn-type]
68 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
449 ms |
548 KB |
Output is correct |
2 |
Correct |
337 ms |
544 KB |
Output is correct |
3 |
Correct |
869 ms |
536 KB |
Output is correct |
4 |
Correct |
591 ms |
532 KB |
Output is correct |
5 |
Correct |
594 ms |
424 KB |
Output is correct |
6 |
Correct |
485 ms |
548 KB |
Output is correct |
7 |
Correct |
458 ms |
572 KB |
Output is correct |
8 |
Correct |
2 ms |
500 KB |
Output is correct |
9 |
Correct |
4 ms |
496 KB |
Output is correct |
10 |
Correct |
0 ms |
500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
409 ms |
680 KB |
Output is correct |
2 |
Correct |
537 ms |
528 KB |
Output is correct |
3 |
Correct |
806 ms |
416 KB |
Output is correct |
4 |
Correct |
654 ms |
420 KB |
Output is correct |
5 |
Correct |
592 ms |
524 KB |
Output is correct |
6 |
Correct |
481 ms |
544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
515 ms |
652 KB |
Output is correct |
2 |
Correct |
472 ms |
548 KB |
Output is correct |
3 |
Correct |
812 ms |
416 KB |
Output is correct |
4 |
Correct |
622 ms |
528 KB |
Output is correct |
5 |
Correct |
552 ms |
420 KB |
Output is correct |
6 |
Correct |
409 ms |
652 KB |
Output is correct |
7 |
Correct |
451 ms |
548 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
4 ms |
500 KB |
Output is correct |
10 |
Correct |
0 ms |
504 KB |
Output is correct |
11 |
Correct |
631 ms |
416 KB |
Output is correct |
12 |
Correct |
433 ms |
640 KB |
Output is correct |
13 |
Correct |
419 ms |
672 KB |
Output is correct |
14 |
Correct |
390 ms |
548 KB |
Output is correct |
15 |
Correct |
57 ms |
600 KB |
Output is correct |
16 |
Correct |
54 ms |
724 KB |
Output is correct |
17 |
Correct |
113 ms |
672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
831 ms |
420 KB |
Output is correct |
2 |
Correct |
702 ms |
528 KB |
Output is correct |
3 |
Correct |
611 ms |
420 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
5 ms |
492 KB |
Output is correct |
6 |
Correct |
0 ms |
488 KB |
Output is correct |
7 |
Correct |
643 ms |
524 KB |
Output is correct |
8 |
Correct |
832 ms |
532 KB |
Output is correct |
9 |
Correct |
627 ms |
528 KB |
Output is correct |
10 |
Correct |
573 ms |
532 KB |
Output is correct |
11 |
Correct |
5 ms |
500 KB |
Output is correct |
12 |
Correct |
4 ms |
500 KB |
Output is correct |
13 |
Correct |
3 ms |
492 KB |
Output is correct |
14 |
Correct |
4 ms |
552 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
481 ms |
420 KB |
Output is correct |
17 |
Correct |
459 ms |
420 KB |
Output is correct |
18 |
Correct |
485 ms |
528 KB |
Output is correct |
19 |
Correct |
540 ms |
416 KB |
Output is correct |
20 |
Correct |
470 ms |
484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
583 ms |
632 KB |
Output is correct |
2 |
Correct |
418 ms |
536 KB |
Output is correct |
3 |
Correct |
778 ms |
420 KB |
Output is correct |
4 |
Correct |
679 ms |
532 KB |
Output is correct |
5 |
Correct |
565 ms |
528 KB |
Output is correct |
6 |
Correct |
418 ms |
532 KB |
Output is correct |
7 |
Correct |
403 ms |
544 KB |
Output is correct |
8 |
Correct |
1 ms |
500 KB |
Output is correct |
9 |
Correct |
3 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
488 KB |
Output is correct |
11 |
Correct |
472 ms |
544 KB |
Output is correct |
12 |
Correct |
528 ms |
536 KB |
Output is correct |
13 |
Correct |
847 ms |
416 KB |
Output is correct |
14 |
Correct |
645 ms |
536 KB |
Output is correct |
15 |
Correct |
563 ms |
532 KB |
Output is correct |
16 |
Correct |
442 ms |
528 KB |
Output is correct |
17 |
Correct |
574 ms |
416 KB |
Output is correct |
18 |
Correct |
460 ms |
676 KB |
Output is correct |
19 |
Correct |
440 ms |
656 KB |
Output is correct |
20 |
Correct |
442 ms |
544 KB |
Output is correct |
21 |
Correct |
51 ms |
444 KB |
Output is correct |
22 |
Correct |
59 ms |
596 KB |
Output is correct |
23 |
Correct |
109 ms |
684 KB |
Output is correct |
24 |
Correct |
5 ms |
492 KB |
Output is correct |
25 |
Correct |
4 ms |
492 KB |
Output is correct |
26 |
Correct |
4 ms |
504 KB |
Output is correct |
27 |
Correct |
3 ms |
492 KB |
Output is correct |
28 |
Correct |
2 ms |
492 KB |
Output is correct |
29 |
Correct |
488 ms |
532 KB |
Output is correct |
30 |
Correct |
488 ms |
416 KB |
Output is correct |
31 |
Correct |
489 ms |
660 KB |
Output is correct |
32 |
Correct |
469 ms |
420 KB |
Output is correct |
33 |
Correct |
454 ms |
420 KB |
Output is correct |
34 |
Correct |
334 ms |
628 KB |
Output is correct |
35 |
Correct |
377 ms |
668 KB |
Output is correct |
36 |
Correct |
442 ms |
640 KB |
Output is correct |
37 |
Correct |
468 ms |
708 KB |
Output is correct |
38 |
Correct |
432 ms |
772 KB |
Output is correct |
39 |
Correct |
366 ms |
644 KB |
Output is correct |
40 |
Correct |
442 ms |
704 KB |
Output is correct |
41 |
Correct |
437 ms |
624 KB |
Output is correct |
42 |
Correct |
53 ms |
672 KB |
Output is correct |
43 |
Correct |
84 ms |
660 KB |
Output is correct |
44 |
Correct |
152 ms |
616 KB |
Output is correct |
45 |
Correct |
128 ms |
528 KB |
Output is correct |
46 |
Correct |
298 ms |
548 KB |
Output is correct |
47 |
Correct |
322 ms |
532 KB |
Output is correct |
48 |
Correct |
62 ms |
792 KB |
Output is correct |
49 |
Correct |
54 ms |
716 KB |
Output is correct |