#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
const int Mx = 1010;
int timer = 0;
void dfs(int node,int par,vector<int> &labels,vector<vector<int>> &tr,bool parity){
if(parity)labels[node] = timer++;
for(auto i:tr[node]){
if(i != par){
dfs(i,node,labels,tr,!parity);
}
}
if(!parity)labels[node] = timer++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
timer = 0;
vector<int> labels(n);
vector<vector<int>> tr(n+1,vector<int>(0));
for (int i = 0; i < n-1; i++) {
tr[u[i]].push_back(v[i]);
tr[v[i]].push_back(u[i]);
}
dfs(0,-1,labels,tr,1);
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
if ((int)c.size() == 1) return c.back();
if (c.front() > s){
// s is tin
int l = s, r = c[(int)c.size() - 2];
if (l > t || r < t) return c.back(); // t out go to parent
int pos = lower_bound(c.begin(), c.end(), t) - c.begin(); // go to subtree where t
return c[pos];
} else {
// s is tout
int l = c[1], r = s;
if (l > t || r < t) return c.front(); // t out go to parent
int pos = upper_bound(c.begin(), c.end(), t) - c.begin() - 1; // go to subtree where t
return c[pos];
}
return c[0];
}
// c sorted
// small c deeper in the tree
// big c high in tree
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
647 ms |
616 KB |
Output is correct |
2 |
Correct |
568 ms |
708 KB |
Output is correct |
3 |
Correct |
1190 ms |
612 KB |
Output is correct |
4 |
Correct |
751 ms |
528 KB |
Output is correct |
5 |
Correct |
589 ms |
512 KB |
Output is correct |
6 |
Correct |
527 ms |
616 KB |
Output is correct |
7 |
Correct |
578 ms |
528 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
5 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
565 ms |
604 KB |
Output is correct |
2 |
Correct |
682 ms |
528 KB |
Output is correct |
3 |
Correct |
1079 ms |
400 KB |
Output is correct |
4 |
Correct |
745 ms |
480 KB |
Output is correct |
5 |
Correct |
705 ms |
484 KB |
Output is correct |
6 |
Correct |
528 ms |
528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
532 ms |
616 KB |
Output is correct |
2 |
Correct |
529 ms |
664 KB |
Output is correct |
3 |
Correct |
1077 ms |
400 KB |
Output is correct |
4 |
Correct |
725 ms |
484 KB |
Output is correct |
5 |
Correct |
656 ms |
488 KB |
Output is correct |
6 |
Correct |
630 ms |
528 KB |
Output is correct |
7 |
Correct |
491 ms |
528 KB |
Output is correct |
8 |
Correct |
3 ms |
472 KB |
Output is correct |
9 |
Correct |
5 ms |
400 KB |
Output is correct |
10 |
Correct |
2 ms |
448 KB |
Output is correct |
11 |
Correct |
707 ms |
496 KB |
Output is correct |
12 |
Correct |
482 ms |
648 KB |
Output is correct |
13 |
Correct |
563 ms |
624 KB |
Output is correct |
14 |
Correct |
491 ms |
488 KB |
Output is correct |
15 |
Correct |
60 ms |
448 KB |
Output is correct |
16 |
Correct |
111 ms |
528 KB |
Output is correct |
17 |
Correct |
134 ms |
572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
958 ms |
400 KB |
Output is correct |
2 |
Correct |
815 ms |
468 KB |
Output is correct |
3 |
Correct |
655 ms |
484 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
472 KB |
Output is correct |
6 |
Correct |
2 ms |
480 KB |
Output is correct |
7 |
Correct |
703 ms |
400 KB |
Output is correct |
8 |
Correct |
971 ms |
456 KB |
Output is correct |
9 |
Correct |
817 ms |
400 KB |
Output is correct |
10 |
Correct |
631 ms |
400 KB |
Output is correct |
11 |
Correct |
6 ms |
468 KB |
Output is correct |
12 |
Correct |
7 ms |
468 KB |
Output is correct |
13 |
Correct |
4 ms |
468 KB |
Output is correct |
14 |
Correct |
5 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
567 ms |
400 KB |
Output is correct |
17 |
Correct |
672 ms |
400 KB |
Output is correct |
18 |
Correct |
544 ms |
404 KB |
Output is correct |
19 |
Correct |
613 ms |
400 KB |
Output is correct |
20 |
Correct |
634 ms |
488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
557 ms |
732 KB |
Output is correct |
2 |
Correct |
604 ms |
528 KB |
Output is correct |
3 |
Correct |
1061 ms |
504 KB |
Output is correct |
4 |
Correct |
804 ms |
400 KB |
Output is correct |
5 |
Correct |
635 ms |
492 KB |
Output is correct |
6 |
Correct |
492 ms |
520 KB |
Output is correct |
7 |
Correct |
576 ms |
528 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
7 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
598 ms |
480 KB |
Output is correct |
12 |
Correct |
572 ms |
488 KB |
Output is correct |
13 |
Correct |
1117 ms |
468 KB |
Output is correct |
14 |
Correct |
739 ms |
400 KB |
Output is correct |
15 |
Correct |
636 ms |
488 KB |
Output is correct |
16 |
Correct |
501 ms |
488 KB |
Output is correct |
17 |
Correct |
562 ms |
484 KB |
Output is correct |
18 |
Correct |
506 ms |
672 KB |
Output is correct |
19 |
Correct |
541 ms |
648 KB |
Output is correct |
20 |
Correct |
538 ms |
656 KB |
Output is correct |
21 |
Correct |
72 ms |
404 KB |
Output is correct |
22 |
Correct |
67 ms |
528 KB |
Output is correct |
23 |
Correct |
116 ms |
556 KB |
Output is correct |
24 |
Correct |
6 ms |
468 KB |
Output is correct |
25 |
Correct |
7 ms |
508 KB |
Output is correct |
26 |
Correct |
7 ms |
464 KB |
Output is correct |
27 |
Correct |
5 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
710 ms |
508 KB |
Output is correct |
30 |
Correct |
590 ms |
488 KB |
Output is correct |
31 |
Correct |
615 ms |
400 KB |
Output is correct |
32 |
Correct |
618 ms |
488 KB |
Output is correct |
33 |
Correct |
510 ms |
488 KB |
Output is correct |
34 |
Correct |
316 ms |
612 KB |
Output is correct |
35 |
Correct |
505 ms |
724 KB |
Output is correct |
36 |
Correct |
568 ms |
724 KB |
Output is correct |
37 |
Correct |
477 ms |
564 KB |
Output is correct |
38 |
Correct |
623 ms |
612 KB |
Output is correct |
39 |
Correct |
531 ms |
604 KB |
Output is correct |
40 |
Correct |
563 ms |
856 KB |
Output is correct |
41 |
Correct |
487 ms |
608 KB |
Output is correct |
42 |
Correct |
62 ms |
528 KB |
Output is correct |
43 |
Correct |
126 ms |
492 KB |
Output is correct |
44 |
Correct |
131 ms |
492 KB |
Output is correct |
45 |
Correct |
195 ms |
488 KB |
Output is correct |
46 |
Correct |
378 ms |
484 KB |
Output is correct |
47 |
Correct |
366 ms |
612 KB |
Output is correct |
48 |
Correct |
56 ms |
528 KB |
Output is correct |
49 |
Correct |
61 ms |
724 KB |
Output is correct |