#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
void dfs(int cur, bool color, int &timer, vector<int> &res, vector<bool> &vis, vector<vector<int> > &g) {
vis[cur] = true;
if(color) {
timer++;
res[cur] = timer;
}
for(int nei : g[cur]) {
if(!vis[nei]) {
dfs(nei, !color, timer, res, vis, g);
}
}
if(!color) {
timer++;
res[cur] = timer;
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
int timer = 0;
vector<int> res(n, 0);
vector<bool> vis(n, false);
vector<vector<int> > g(n);
for(int i = 0; i < n - 1; i++) {
g[u[i]].pb(v[i]);
g[v[i]].pb(u[i]);
}
dfs(0, true, timer, res, vis, g);
/*for(int x : res) {
cout << x << " ";
}
cout << "\n";*/
return res;
}
#define ans(x) int tmp = (to_swap ? ceil - x : x); /*cout << "Answer: " << tmp << "\n";*/ return tmp;
int find_next_station(int s, int t, vector<int> c) {
/*cout << "Question:\n";
cout << s << " " << t << "\n";
for(int x : c) {
cout << x << " ";
}
cout << "\n";*/
if(s == 1) {
for(int &x : c) {
if(t <= x) {
//cout << "Answer: " << x << "\n";
return x;
}
}
}
bool to_swap = false;
int ceil = max({s, t, *max_element(c.begin(), c.end())}) + 1;
if(c[0] < s) {
to_swap = true;
s = ceil - s;
t = ceil - t;
for(int &x : c) {
x = ceil - x;
}
reverse(c.begin(), c.end());
}
int p = c.back();
c.resize((int) c.size() - 1);
if(t < s) {
ans(p);
}
for(int &x : c) {
if(t <= x) {
ans(x);
}
}
ans(p);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
635 ms |
624 KB |
Output is correct |
2 |
Correct |
671 ms |
628 KB |
Output is correct |
3 |
Correct |
1006 ms |
528 KB |
Output is correct |
4 |
Correct |
931 ms |
416 KB |
Output is correct |
5 |
Correct |
679 ms |
416 KB |
Output is correct |
6 |
Correct |
493 ms |
544 KB |
Output is correct |
7 |
Correct |
496 ms |
500 KB |
Output is correct |
8 |
Correct |
3 ms |
492 KB |
Output is correct |
9 |
Correct |
3 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
542 ms |
504 KB |
Output is correct |
2 |
Correct |
515 ms |
544 KB |
Output is correct |
3 |
Correct |
911 ms |
500 KB |
Output is correct |
4 |
Correct |
788 ms |
416 KB |
Output is correct |
5 |
Correct |
606 ms |
420 KB |
Output is correct |
6 |
Correct |
372 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
457 ms |
652 KB |
Output is correct |
2 |
Correct |
447 ms |
672 KB |
Output is correct |
3 |
Correct |
902 ms |
536 KB |
Output is correct |
4 |
Correct |
649 ms |
504 KB |
Output is correct |
5 |
Correct |
566 ms |
420 KB |
Output is correct |
6 |
Correct |
359 ms |
632 KB |
Output is correct |
7 |
Correct |
411 ms |
544 KB |
Output is correct |
8 |
Correct |
3 ms |
492 KB |
Output is correct |
9 |
Correct |
4 ms |
500 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
623 ms |
508 KB |
Output is correct |
12 |
Correct |
451 ms |
628 KB |
Output is correct |
13 |
Correct |
436 ms |
620 KB |
Output is correct |
14 |
Correct |
435 ms |
548 KB |
Output is correct |
15 |
Correct |
50 ms |
440 KB |
Output is correct |
16 |
Correct |
54 ms |
508 KB |
Output is correct |
17 |
Correct |
95 ms |
544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
770 ms |
496 KB |
Output is correct |
2 |
Correct |
572 ms |
500 KB |
Output is correct |
3 |
Correct |
717 ms |
500 KB |
Output is correct |
4 |
Correct |
2 ms |
496 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Correct |
572 ms |
416 KB |
Output is correct |
8 |
Correct |
803 ms |
416 KB |
Output is correct |
9 |
Correct |
641 ms |
416 KB |
Output is correct |
10 |
Correct |
646 ms |
504 KB |
Output is correct |
11 |
Correct |
6 ms |
496 KB |
Output is correct |
12 |
Correct |
6 ms |
492 KB |
Output is correct |
13 |
Correct |
4 ms |
492 KB |
Output is correct |
14 |
Correct |
3 ms |
492 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
525 ms |
504 KB |
Output is correct |
17 |
Correct |
482 ms |
504 KB |
Output is correct |
18 |
Correct |
426 ms |
420 KB |
Output is correct |
19 |
Correct |
528 ms |
508 KB |
Output is correct |
20 |
Correct |
469 ms |
420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
584 ms |
656 KB |
Output is correct |
2 |
Correct |
454 ms |
636 KB |
Output is correct |
3 |
Correct |
918 ms |
500 KB |
Output is correct |
4 |
Correct |
683 ms |
512 KB |
Output is correct |
5 |
Correct |
512 ms |
420 KB |
Output is correct |
6 |
Correct |
457 ms |
660 KB |
Output is correct |
7 |
Correct |
429 ms |
548 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
3 ms |
500 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
496 ms |
504 KB |
Output is correct |
12 |
Correct |
498 ms |
504 KB |
Output is correct |
13 |
Correct |
890 ms |
428 KB |
Output is correct |
14 |
Correct |
620 ms |
416 KB |
Output is correct |
15 |
Correct |
639 ms |
504 KB |
Output is correct |
16 |
Correct |
473 ms |
504 KB |
Output is correct |
17 |
Correct |
587 ms |
420 KB |
Output is correct |
18 |
Correct |
462 ms |
692 KB |
Output is correct |
19 |
Correct |
411 ms |
712 KB |
Output is correct |
20 |
Correct |
472 ms |
540 KB |
Output is correct |
21 |
Correct |
52 ms |
444 KB |
Output is correct |
22 |
Correct |
70 ms |
572 KB |
Output is correct |
23 |
Correct |
96 ms |
504 KB |
Output is correct |
24 |
Correct |
8 ms |
492 KB |
Output is correct |
25 |
Correct |
6 ms |
492 KB |
Output is correct |
26 |
Correct |
2 ms |
492 KB |
Output is correct |
27 |
Correct |
4 ms |
492 KB |
Output is correct |
28 |
Correct |
2 ms |
492 KB |
Output is correct |
29 |
Correct |
422 ms |
508 KB |
Output is correct |
30 |
Correct |
510 ms |
416 KB |
Output is correct |
31 |
Correct |
473 ms |
416 KB |
Output is correct |
32 |
Correct |
474 ms |
416 KB |
Output is correct |
33 |
Correct |
482 ms |
420 KB |
Output is correct |
34 |
Correct |
270 ms |
620 KB |
Output is correct |
35 |
Correct |
368 ms |
636 KB |
Output is correct |
36 |
Correct |
406 ms |
716 KB |
Output is correct |
37 |
Correct |
432 ms |
628 KB |
Output is correct |
38 |
Correct |
428 ms |
616 KB |
Output is correct |
39 |
Correct |
451 ms |
588 KB |
Output is correct |
40 |
Correct |
441 ms |
596 KB |
Output is correct |
41 |
Correct |
410 ms |
752 KB |
Output is correct |
42 |
Correct |
65 ms |
548 KB |
Output is correct |
43 |
Correct |
90 ms |
544 KB |
Output is correct |
44 |
Correct |
127 ms |
548 KB |
Output is correct |
45 |
Correct |
156 ms |
548 KB |
Output is correct |
46 |
Correct |
292 ms |
512 KB |
Output is correct |
47 |
Correct |
295 ms |
544 KB |
Output is correct |
48 |
Correct |
68 ms |
532 KB |
Output is correct |
49 |
Correct |
41 ms |
672 KB |
Output is correct |