#include<bits/stdc++.h>
#include "stations.h"
using namespace std;
using ll = long long;
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
std::vector<int> labels(n), subs(n);
vector<vector<int>> adj(n);
for (int i = 0; i < n - 1; i++)
adj[u[i]].push_back(v[i]),
adj[v[i]].push_back(u[i]);
auto dfs_s = [&](auto& dfs, int i, int p)->void {
subs[i] = 1;
for (int e : adj[i]) {
if (e != p) {
dfs(dfs, e, i);
subs[i] += subs[e];
}
}
};
dfs_s(dfs_s, 0, -1);
auto dfs = [&](auto& dfs, int i, int p, int dep, int l, int r)->void {
for (int e : adj[i]) {
if (e == p) continue;
int nl, nr;
if (dep % 2 == 0) {
nl = r - subs[e] + 1;
nr = r;
r -= subs[e];
} else {
nl = l;
nr = l + subs[e] - 1;
l += subs[e];
}
dfs(dfs, e, i, dep+1, nl, nr);
}
assert(l == r);
labels[i] = l;
};
dfs(dfs, 0, -1, 0, 0, n-1);
// for (int i : labels) cout << i << ' '; cout << endl;
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
sort(c.begin(), c.end());
if (s == 0) {// root
for (int i : c) {
if (t <= i) return i;
}
assert(false);
}
if (c[0] < s) { // left-right-left
int par = c[0];
if (s < t) return par;
c.erase(c.begin());
reverse(c.begin(), c.end());
for (int j : c) {
if (j <= t) return j;
}
return par;
} else {//right-left-right
reverse(c.begin(), c.end());
int par = c[0];
if (t < s) return par;
c.erase(c.begin());
reverse(c.begin(), c.end());
for (int j : c) {
if (t <= j) return j;
}
return par;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
448 ms |
548 KB |
Output is correct |
2 |
Correct |
312 ms |
508 KB |
Output is correct |
3 |
Correct |
667 ms |
512 KB |
Output is correct |
4 |
Correct |
442 ms |
416 KB |
Output is correct |
5 |
Correct |
534 ms |
548 KB |
Output is correct |
6 |
Correct |
411 ms |
544 KB |
Output is correct |
7 |
Correct |
396 ms |
508 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
357 ms |
504 KB |
Output is correct |
2 |
Correct |
454 ms |
516 KB |
Output is correct |
3 |
Correct |
650 ms |
420 KB |
Output is correct |
4 |
Correct |
527 ms |
572 KB |
Output is correct |
5 |
Correct |
474 ms |
464 KB |
Output is correct |
6 |
Correct |
368 ms |
508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
510 ms |
628 KB |
Output is correct |
2 |
Correct |
369 ms |
508 KB |
Output is correct |
3 |
Correct |
760 ms |
504 KB |
Output is correct |
4 |
Correct |
636 ms |
416 KB |
Output is correct |
5 |
Correct |
471 ms |
508 KB |
Output is correct |
6 |
Correct |
446 ms |
684 KB |
Output is correct |
7 |
Correct |
351 ms |
508 KB |
Output is correct |
8 |
Correct |
2 ms |
544 KB |
Output is correct |
9 |
Correct |
3 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
500 KB |
Output is correct |
11 |
Correct |
457 ms |
532 KB |
Output is correct |
12 |
Correct |
341 ms |
704 KB |
Output is correct |
13 |
Correct |
428 ms |
704 KB |
Output is correct |
14 |
Correct |
316 ms |
616 KB |
Output is correct |
15 |
Correct |
32 ms |
540 KB |
Output is correct |
16 |
Correct |
41 ms |
612 KB |
Output is correct |
17 |
Correct |
75 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
606 ms |
564 KB |
Output is correct |
2 |
Correct |
577 ms |
504 KB |
Output is correct |
3 |
Correct |
418 ms |
532 KB |
Output is correct |
4 |
Correct |
2 ms |
552 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
489 ms |
416 KB |
Output is correct |
8 |
Correct |
587 ms |
416 KB |
Output is correct |
9 |
Correct |
462 ms |
508 KB |
Output is correct |
10 |
Correct |
423 ms |
500 KB |
Output is correct |
11 |
Correct |
2 ms |
500 KB |
Output is correct |
12 |
Correct |
3 ms |
492 KB |
Output is correct |
13 |
Correct |
3 ms |
500 KB |
Output is correct |
14 |
Correct |
2 ms |
492 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
352 ms |
544 KB |
Output is correct |
17 |
Correct |
444 ms |
504 KB |
Output is correct |
18 |
Correct |
401 ms |
416 KB |
Output is correct |
19 |
Correct |
427 ms |
416 KB |
Output is correct |
20 |
Correct |
359 ms |
544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
383 ms |
548 KB |
Output is correct |
2 |
Correct |
284 ms |
700 KB |
Output is correct |
3 |
Correct |
682 ms |
416 KB |
Output is correct |
4 |
Correct |
496 ms |
416 KB |
Output is correct |
5 |
Correct |
514 ms |
416 KB |
Output is correct |
6 |
Correct |
411 ms |
628 KB |
Output is correct |
7 |
Correct |
346 ms |
508 KB |
Output is correct |
8 |
Correct |
3 ms |
492 KB |
Output is correct |
9 |
Correct |
3 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
488 KB |
Output is correct |
11 |
Correct |
384 ms |
544 KB |
Output is correct |
12 |
Correct |
569 ms |
548 KB |
Output is correct |
13 |
Correct |
636 ms |
504 KB |
Output is correct |
14 |
Correct |
467 ms |
504 KB |
Output is correct |
15 |
Correct |
449 ms |
500 KB |
Output is correct |
16 |
Correct |
341 ms |
544 KB |
Output is correct |
17 |
Correct |
484 ms |
500 KB |
Output is correct |
18 |
Correct |
344 ms |
548 KB |
Output is correct |
19 |
Correct |
351 ms |
700 KB |
Output is correct |
20 |
Correct |
351 ms |
544 KB |
Output is correct |
21 |
Correct |
52 ms |
444 KB |
Output is correct |
22 |
Correct |
57 ms |
620 KB |
Output is correct |
23 |
Correct |
92 ms |
544 KB |
Output is correct |
24 |
Correct |
5 ms |
492 KB |
Output is correct |
25 |
Correct |
4 ms |
492 KB |
Output is correct |
26 |
Correct |
3 ms |
492 KB |
Output is correct |
27 |
Correct |
3 ms |
440 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
393 ms |
420 KB |
Output is correct |
30 |
Correct |
375 ms |
416 KB |
Output is correct |
31 |
Correct |
385 ms |
420 KB |
Output is correct |
32 |
Correct |
426 ms |
512 KB |
Output is correct |
33 |
Correct |
418 ms |
420 KB |
Output is correct |
34 |
Correct |
280 ms |
504 KB |
Output is correct |
35 |
Correct |
262 ms |
628 KB |
Output is correct |
36 |
Correct |
371 ms |
620 KB |
Output is correct |
37 |
Correct |
378 ms |
592 KB |
Output is correct |
38 |
Correct |
328 ms |
604 KB |
Output is correct |
39 |
Correct |
415 ms |
716 KB |
Output is correct |
40 |
Correct |
350 ms |
752 KB |
Output is correct |
41 |
Correct |
403 ms |
632 KB |
Output is correct |
42 |
Correct |
58 ms |
600 KB |
Output is correct |
43 |
Correct |
67 ms |
616 KB |
Output is correct |
44 |
Correct |
131 ms |
504 KB |
Output is correct |
45 |
Correct |
106 ms |
544 KB |
Output is correct |
46 |
Correct |
243 ms |
508 KB |
Output is correct |
47 |
Correct |
187 ms |
504 KB |
Output is correct |
48 |
Correct |
44 ms |
760 KB |
Output is correct |
49 |
Correct |
45 ms |
660 KB |
Output is correct |