#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 10;
int t;
vector<int> labels, adj[MAXN];
void dfs(int v, int p, bool b) {
if (b) labels[v] = t++;
for (int u : adj[v])
if (u != p)
dfs(u, v, !b);
if (!b) labels[v] = t++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
for (int i = 0; i < MAXN; i++)
adj[i].clear();
t = 0;
labels.resize(n);
for (int i = 0; i < n - 1; i++) {
int a = u[i], b = v[i];
adj[a].push_back(b);
adj[b].push_back(a);
}
dfs(0, 0, true);
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
sort(c.begin(), c.end());
bool f = s < c[0];
int n = c.size();
if (f) {
if (t < s) return c[n - 1];
for (int i = 0; i < n - 1; i++)
if (t <= c[i])
return c[i];
return c[n - 1];
} else {
if (t > s) return c[0];
for (int i = n - 1; i > 0; i--)
if (c[i] <= t)
return c[i];
return c[0];
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
499 ms |
656 KB |
Output is correct |
2 |
Correct |
371 ms |
548 KB |
Output is correct |
3 |
Correct |
698 ms |
416 KB |
Output is correct |
4 |
Correct |
477 ms |
416 KB |
Output is correct |
5 |
Correct |
587 ms |
416 KB |
Output is correct |
6 |
Correct |
313 ms |
644 KB |
Output is correct |
7 |
Correct |
439 ms |
552 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
3 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
385 ms |
652 KB |
Output is correct |
2 |
Correct |
418 ms |
544 KB |
Output is correct |
3 |
Correct |
659 ms |
504 KB |
Output is correct |
4 |
Correct |
540 ms |
416 KB |
Output is correct |
5 |
Correct |
479 ms |
416 KB |
Output is correct |
6 |
Correct |
374 ms |
532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
408 ms |
672 KB |
Output is correct |
2 |
Correct |
372 ms |
664 KB |
Output is correct |
3 |
Correct |
669 ms |
416 KB |
Output is correct |
4 |
Correct |
459 ms |
532 KB |
Output is correct |
5 |
Correct |
418 ms |
528 KB |
Output is correct |
6 |
Correct |
339 ms |
660 KB |
Output is correct |
7 |
Correct |
291 ms |
548 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
2 ms |
500 KB |
Output is correct |
10 |
Correct |
0 ms |
488 KB |
Output is correct |
11 |
Correct |
410 ms |
532 KB |
Output is correct |
12 |
Correct |
313 ms |
656 KB |
Output is correct |
13 |
Correct |
316 ms |
760 KB |
Output is correct |
14 |
Correct |
400 ms |
544 KB |
Output is correct |
15 |
Correct |
36 ms |
492 KB |
Output is correct |
16 |
Correct |
53 ms |
568 KB |
Output is correct |
17 |
Correct |
95 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
788 ms |
528 KB |
Output is correct |
2 |
Correct |
554 ms |
464 KB |
Output is correct |
3 |
Correct |
505 ms |
416 KB |
Output is correct |
4 |
Correct |
1 ms |
496 KB |
Output is correct |
5 |
Correct |
1 ms |
488 KB |
Output is correct |
6 |
Correct |
0 ms |
492 KB |
Output is correct |
7 |
Correct |
461 ms |
416 KB |
Output is correct |
8 |
Correct |
773 ms |
524 KB |
Output is correct |
9 |
Correct |
490 ms |
544 KB |
Output is correct |
10 |
Correct |
465 ms |
416 KB |
Output is correct |
11 |
Correct |
4 ms |
500 KB |
Output is correct |
12 |
Correct |
5 ms |
492 KB |
Output is correct |
13 |
Correct |
3 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
516 KB |
Output is correct |
15 |
Correct |
1 ms |
500 KB |
Output is correct |
16 |
Correct |
487 ms |
524 KB |
Output is correct |
17 |
Correct |
353 ms |
420 KB |
Output is correct |
18 |
Correct |
349 ms |
420 KB |
Output is correct |
19 |
Correct |
283 ms |
416 KB |
Output is correct |
20 |
Correct |
492 ms |
448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
464 ms |
676 KB |
Output is correct |
2 |
Correct |
245 ms |
544 KB |
Output is correct |
3 |
Correct |
709 ms |
544 KB |
Output is correct |
4 |
Correct |
486 ms |
552 KB |
Output is correct |
5 |
Correct |
479 ms |
416 KB |
Output is correct |
6 |
Correct |
353 ms |
656 KB |
Output is correct |
7 |
Correct |
325 ms |
532 KB |
Output is correct |
8 |
Correct |
1 ms |
500 KB |
Output is correct |
9 |
Correct |
3 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
299 ms |
576 KB |
Output is correct |
12 |
Correct |
320 ms |
548 KB |
Output is correct |
13 |
Correct |
612 ms |
544 KB |
Output is correct |
14 |
Correct |
430 ms |
528 KB |
Output is correct |
15 |
Correct |
591 ms |
524 KB |
Output is correct |
16 |
Correct |
369 ms |
548 KB |
Output is correct |
17 |
Correct |
467 ms |
416 KB |
Output is correct |
18 |
Correct |
305 ms |
736 KB |
Output is correct |
19 |
Correct |
343 ms |
756 KB |
Output is correct |
20 |
Correct |
424 ms |
544 KB |
Output is correct |
21 |
Correct |
40 ms |
416 KB |
Output is correct |
22 |
Correct |
55 ms |
660 KB |
Output is correct |
23 |
Correct |
124 ms |
664 KB |
Output is correct |
24 |
Correct |
4 ms |
540 KB |
Output is correct |
25 |
Correct |
3 ms |
512 KB |
Output is correct |
26 |
Correct |
3 ms |
492 KB |
Output is correct |
27 |
Correct |
2 ms |
492 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
336 ms |
416 KB |
Output is correct |
30 |
Correct |
464 ms |
528 KB |
Output is correct |
31 |
Correct |
464 ms |
532 KB |
Output is correct |
32 |
Correct |
422 ms |
528 KB |
Output is correct |
33 |
Correct |
344 ms |
416 KB |
Output is correct |
34 |
Correct |
239 ms |
544 KB |
Output is correct |
35 |
Correct |
313 ms |
876 KB |
Output is correct |
36 |
Correct |
404 ms |
676 KB |
Output is correct |
37 |
Correct |
333 ms |
652 KB |
Output is correct |
38 |
Correct |
404 ms |
796 KB |
Output is correct |
39 |
Correct |
263 ms |
656 KB |
Output is correct |
40 |
Correct |
336 ms |
648 KB |
Output is correct |
41 |
Correct |
359 ms |
664 KB |
Output is correct |
42 |
Correct |
42 ms |
620 KB |
Output is correct |
43 |
Correct |
94 ms |
628 KB |
Output is correct |
44 |
Correct |
96 ms |
548 KB |
Output is correct |
45 |
Correct |
150 ms |
548 KB |
Output is correct |
46 |
Correct |
218 ms |
572 KB |
Output is correct |
47 |
Correct |
187 ms |
544 KB |
Output is correct |
48 |
Correct |
56 ms |
728 KB |
Output is correct |
49 |
Correct |
41 ms |
828 KB |
Output is correct |