#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
int idx;
vector<int> dep, in, out;
vector<vector<int> > adj;
void dfs(int u, int e = -1) {
in[u] = idx++;
for (auto v : adj[u]) if (v != e) {
dep[v] = dep[u] + 1;
dfs(v, u);
}
out[u] = idx++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
dep = in = out = vector<int>(n, 0);
adj = vector<vector<int> >(n);
for (int i = 0; i < (int)u.size(); i++) {
adj[u[i]].pb(v[i]);
adj[v[i]].pb(u[i]);
}
assert(dep[0] == 0);
dfs(0);
assert(dep[0] == 0);
vector<int> lab(n), vals(n);
for (int i = 0; i < n; i++) {
lab[i] = (dep[i] % 2 == 0 ? in[i] : out[i]);
vals[i] = lab[i];
}
sort(vals.begin(), vals.end());
assert(unique(vals.begin(), vals.end()) == vals.end());
for (int i = 0; i < n; i++) {
lab[i] = lower_bound(vals.begin(), vals.end(), lab[i]) - vals.begin();
}
for (int i = 0; i < n; i++) {
adj[i].clear();
}
dep.clear();
in.clear();
out.clear();
idx = 0;
return lab;
}
int find_next_station(int s, int t, vector<int> c) {
if (binary_search(c.begin(), c.end(), t)) {
return t;
}
if (s == 0) {
for (int i = 0; i < (int)c.size(); i++) {
if (t <= c[i]) {
return c[i];
}
}
assert(0);
} else if (s < *min_element(c.begin(), c.end())) {
for (int i = 0; i + 1 < (int)c.size(); i++) {
if (s < t && t <= c[i]) {
return c[i];
}
}
return c.back();
} else {
assert(*max_element(c.begin(), c.end()) < s);
for (int i = 1; i < (int)c.size(); i++) {
if (((i + 1 == (int)c.size() && t < s) || (i + 1 < (int)c.size() && c[i + 1] > t)) && t >= c[i]) {
return c[i];
}
}
return c[0];
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
456 ms |
676 KB |
Output is correct |
2 |
Correct |
341 ms |
672 KB |
Output is correct |
3 |
Correct |
714 ms |
416 KB |
Output is correct |
4 |
Correct |
619 ms |
532 KB |
Output is correct |
5 |
Correct |
533 ms |
500 KB |
Output is correct |
6 |
Correct |
299 ms |
632 KB |
Output is correct |
7 |
Correct |
307 ms |
544 KB |
Output is correct |
8 |
Correct |
2 ms |
660 KB |
Output is correct |
9 |
Correct |
3 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
328 ms |
672 KB |
Output is correct |
2 |
Correct |
446 ms |
544 KB |
Output is correct |
3 |
Correct |
730 ms |
508 KB |
Output is correct |
4 |
Correct |
527 ms |
420 KB |
Output is correct |
5 |
Correct |
391 ms |
504 KB |
Output is correct |
6 |
Correct |
310 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
348 ms |
684 KB |
Output is correct |
2 |
Correct |
350 ms |
632 KB |
Output is correct |
3 |
Correct |
750 ms |
496 KB |
Output is correct |
4 |
Correct |
470 ms |
416 KB |
Output is correct |
5 |
Correct |
562 ms |
500 KB |
Output is correct |
6 |
Correct |
406 ms |
624 KB |
Output is correct |
7 |
Correct |
379 ms |
632 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
4 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
496 KB |
Output is correct |
11 |
Correct |
363 ms |
420 KB |
Output is correct |
12 |
Correct |
431 ms |
720 KB |
Output is correct |
13 |
Correct |
388 ms |
752 KB |
Output is correct |
14 |
Correct |
392 ms |
512 KB |
Output is correct |
15 |
Correct |
48 ms |
484 KB |
Output is correct |
16 |
Correct |
41 ms |
544 KB |
Output is correct |
17 |
Correct |
85 ms |
508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
673 ms |
500 KB |
Output is correct |
2 |
Correct |
636 ms |
504 KB |
Output is correct |
3 |
Correct |
444 ms |
508 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
0 ms |
492 KB |
Output is correct |
7 |
Correct |
527 ms |
504 KB |
Output is correct |
8 |
Correct |
716 ms |
500 KB |
Output is correct |
9 |
Correct |
474 ms |
420 KB |
Output is correct |
10 |
Correct |
474 ms |
508 KB |
Output is correct |
11 |
Correct |
4 ms |
492 KB |
Output is correct |
12 |
Correct |
3 ms |
492 KB |
Output is correct |
13 |
Correct |
3 ms |
492 KB |
Output is correct |
14 |
Correct |
2 ms |
500 KB |
Output is correct |
15 |
Correct |
0 ms |
492 KB |
Output is correct |
16 |
Correct |
454 ms |
508 KB |
Output is correct |
17 |
Correct |
323 ms |
504 KB |
Output is correct |
18 |
Correct |
461 ms |
508 KB |
Output is correct |
19 |
Correct |
470 ms |
504 KB |
Output is correct |
20 |
Correct |
331 ms |
568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
436 ms |
628 KB |
Output is correct |
2 |
Correct |
413 ms |
756 KB |
Output is correct |
3 |
Correct |
664 ms |
508 KB |
Output is correct |
4 |
Correct |
527 ms |
504 KB |
Output is correct |
5 |
Correct |
503 ms |
500 KB |
Output is correct |
6 |
Correct |
491 ms |
680 KB |
Output is correct |
7 |
Correct |
360 ms |
548 KB |
Output is correct |
8 |
Correct |
3 ms |
492 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
492 KB |
Output is correct |
11 |
Correct |
387 ms |
616 KB |
Output is correct |
12 |
Correct |
411 ms |
508 KB |
Output is correct |
13 |
Correct |
810 ms |
420 KB |
Output is correct |
14 |
Correct |
564 ms |
500 KB |
Output is correct |
15 |
Correct |
444 ms |
416 KB |
Output is correct |
16 |
Correct |
342 ms |
548 KB |
Output is correct |
17 |
Correct |
549 ms |
500 KB |
Output is correct |
18 |
Correct |
431 ms |
756 KB |
Output is correct |
19 |
Correct |
431 ms |
748 KB |
Output is correct |
20 |
Correct |
330 ms |
544 KB |
Output is correct |
21 |
Correct |
45 ms |
472 KB |
Output is correct |
22 |
Correct |
64 ms |
544 KB |
Output is correct |
23 |
Correct |
78 ms |
600 KB |
Output is correct |
24 |
Correct |
3 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 |
2 ms |
500 KB |
Output is correct |
28 |
Correct |
1 ms |
472 KB |
Output is correct |
29 |
Correct |
359 ms |
544 KB |
Output is correct |
30 |
Correct |
370 ms |
420 KB |
Output is correct |
31 |
Correct |
373 ms |
528 KB |
Output is correct |
32 |
Correct |
367 ms |
416 KB |
Output is correct |
33 |
Correct |
427 ms |
636 KB |
Output is correct |
34 |
Correct |
238 ms |
676 KB |
Output is correct |
35 |
Correct |
404 ms |
636 KB |
Output is correct |
36 |
Correct |
287 ms |
708 KB |
Output is correct |
37 |
Correct |
310 ms |
624 KB |
Output is correct |
38 |
Correct |
389 ms |
712 KB |
Output is correct |
39 |
Correct |
413 ms |
756 KB |
Output is correct |
40 |
Correct |
300 ms |
720 KB |
Output is correct |
41 |
Correct |
426 ms |
720 KB |
Output is correct |
42 |
Correct |
64 ms |
672 KB |
Output is correct |
43 |
Correct |
65 ms |
544 KB |
Output is correct |
44 |
Correct |
99 ms |
548 KB |
Output is correct |
45 |
Correct |
106 ms |
572 KB |
Output is correct |
46 |
Correct |
217 ms |
504 KB |
Output is correct |
47 |
Correct |
219 ms |
676 KB |
Output is correct |
48 |
Correct |
56 ms |
548 KB |
Output is correct |
49 |
Correct |
53 ms |
672 KB |
Output is correct |