#include "stations.h"
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define svec(x) sort(all(x))
#define press(x) x.erase(unique(all(x)), x.end());
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
typedef pair<LL, LL> pll;
const int INF=1e9;
const LL LLINF=1e18;
int n, re;
vector<int> link[1010], lab, id;
void dfs(int num, int par, int d){
re++;
if(d)lab[num-1]=re;
for(auto i:link[num]){
if(i==par)continue;
dfs(i, num, (d+1)%2);
}
if(!d)lab[num-1]=re;
re++;
}
vector<int> label(int _n, int k, vector<int> u, vector<int> v){
n=_n;
lab.clear();
id.clear();
lab.resize(n);
re=0;
for(int i=0; i<n-1; i++){
link[u[i]+1].eb(v[i]+1);
link[v[i]+1].eb(u[i]+1);
}
dfs(1, 0, 1);
for(int i=1; i<=n; i++)link[i].clear();
for(auto i:lab)id.eb(i);
svec(id); press(id);
for(auto &i:lab)i=lower_bound(all(id), i)-id.begin();
return lab;
}
int find_next_station(int s, int t, vector<int> c){
if(s>c.back())reverse(all(c));
for(auto i:c){
if(min(i, s)<=t&&t<=max(i, s))return i;
}
return c.back();
}
/*
1
5 10
0 1
1 2
1 3
2 4
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
556 ms |
1024 KB |
Output is correct |
2 |
Correct |
451 ms |
1016 KB |
Output is correct |
3 |
Correct |
1007 ms |
768 KB |
Output is correct |
4 |
Correct |
905 ms |
896 KB |
Output is correct |
5 |
Correct |
673 ms |
780 KB |
Output is correct |
6 |
Correct |
523 ms |
1024 KB |
Output is correct |
7 |
Correct |
627 ms |
768 KB |
Output is correct |
8 |
Correct |
2 ms |
800 KB |
Output is correct |
9 |
Correct |
5 ms |
872 KB |
Output is correct |
10 |
Correct |
2 ms |
776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
469 ms |
768 KB |
Output is correct |
2 |
Correct |
585 ms |
768 KB |
Output is correct |
3 |
Correct |
965 ms |
768 KB |
Output is correct |
4 |
Correct |
917 ms |
768 KB |
Output is correct |
5 |
Correct |
681 ms |
768 KB |
Output is correct |
6 |
Correct |
480 ms |
800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
728 ms |
1024 KB |
Output is correct |
2 |
Correct |
515 ms |
1008 KB |
Output is correct |
3 |
Correct |
1043 ms |
896 KB |
Output is correct |
4 |
Correct |
796 ms |
780 KB |
Output is correct |
5 |
Correct |
666 ms |
776 KB |
Output is correct |
6 |
Correct |
585 ms |
1024 KB |
Output is correct |
7 |
Correct |
537 ms |
1032 KB |
Output is correct |
8 |
Correct |
3 ms |
744 KB |
Output is correct |
9 |
Correct |
5 ms |
896 KB |
Output is correct |
10 |
Correct |
2 ms |
768 KB |
Output is correct |
11 |
Correct |
845 ms |
784 KB |
Output is correct |
12 |
Correct |
574 ms |
1008 KB |
Output is correct |
13 |
Correct |
682 ms |
1024 KB |
Output is correct |
14 |
Correct |
635 ms |
768 KB |
Output is correct |
15 |
Correct |
69 ms |
768 KB |
Output is correct |
16 |
Correct |
73 ms |
776 KB |
Output is correct |
17 |
Correct |
132 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1170 ms |
780 KB |
Output is correct |
2 |
Correct |
868 ms |
768 KB |
Output is correct |
3 |
Correct |
675 ms |
792 KB |
Output is correct |
4 |
Correct |
3 ms |
896 KB |
Output is correct |
5 |
Correct |
4 ms |
768 KB |
Output is correct |
6 |
Correct |
2 ms |
904 KB |
Output is correct |
7 |
Correct |
771 ms |
768 KB |
Output is correct |
8 |
Correct |
1228 ms |
784 KB |
Output is correct |
9 |
Correct |
838 ms |
768 KB |
Output is correct |
10 |
Correct |
626 ms |
776 KB |
Output is correct |
11 |
Correct |
6 ms |
768 KB |
Output is correct |
12 |
Correct |
4 ms |
672 KB |
Output is correct |
13 |
Correct |
4 ms |
768 KB |
Output is correct |
14 |
Correct |
5 ms |
768 KB |
Output is correct |
15 |
Correct |
2 ms |
768 KB |
Output is correct |
16 |
Correct |
604 ms |
876 KB |
Output is correct |
17 |
Correct |
655 ms |
784 KB |
Output is correct |
18 |
Correct |
619 ms |
768 KB |
Output is correct |
19 |
Correct |
583 ms |
768 KB |
Output is correct |
20 |
Correct |
707 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
684 ms |
1024 KB |
Output is correct |
2 |
Correct |
743 ms |
1024 KB |
Output is correct |
3 |
Correct |
976 ms |
784 KB |
Output is correct |
4 |
Correct |
713 ms |
768 KB |
Output is correct |
5 |
Correct |
704 ms |
896 KB |
Output is correct |
6 |
Correct |
591 ms |
1048 KB |
Output is correct |
7 |
Correct |
645 ms |
768 KB |
Output is correct |
8 |
Correct |
3 ms |
776 KB |
Output is correct |
9 |
Correct |
3 ms |
808 KB |
Output is correct |
10 |
Correct |
1 ms |
776 KB |
Output is correct |
11 |
Correct |
585 ms |
768 KB |
Output is correct |
12 |
Correct |
578 ms |
940 KB |
Output is correct |
13 |
Correct |
996 ms |
768 KB |
Output is correct |
14 |
Correct |
838 ms |
776 KB |
Output is correct |
15 |
Correct |
687 ms |
768 KB |
Output is correct |
16 |
Correct |
522 ms |
768 KB |
Output is correct |
17 |
Correct |
692 ms |
800 KB |
Output is correct |
18 |
Correct |
516 ms |
936 KB |
Output is correct |
19 |
Correct |
569 ms |
1024 KB |
Output is correct |
20 |
Correct |
589 ms |
896 KB |
Output is correct |
21 |
Correct |
52 ms |
928 KB |
Output is correct |
22 |
Correct |
113 ms |
768 KB |
Output is correct |
23 |
Correct |
147 ms |
896 KB |
Output is correct |
24 |
Correct |
6 ms |
896 KB |
Output is correct |
25 |
Correct |
9 ms |
768 KB |
Output is correct |
26 |
Correct |
5 ms |
896 KB |
Output is correct |
27 |
Correct |
6 ms |
768 KB |
Output is correct |
28 |
Correct |
2 ms |
768 KB |
Output is correct |
29 |
Correct |
673 ms |
896 KB |
Output is correct |
30 |
Correct |
623 ms |
768 KB |
Output is correct |
31 |
Correct |
667 ms |
768 KB |
Output is correct |
32 |
Correct |
542 ms |
768 KB |
Output is correct |
33 |
Correct |
567 ms |
784 KB |
Output is correct |
34 |
Correct |
438 ms |
1024 KB |
Output is correct |
35 |
Correct |
564 ms |
1024 KB |
Output is correct |
36 |
Correct |
645 ms |
1024 KB |
Output is correct |
37 |
Correct |
682 ms |
900 KB |
Output is correct |
38 |
Correct |
511 ms |
880 KB |
Output is correct |
39 |
Correct |
608 ms |
1024 KB |
Output is correct |
40 |
Correct |
583 ms |
792 KB |
Output is correct |
41 |
Correct |
587 ms |
896 KB |
Output is correct |
42 |
Correct |
94 ms |
896 KB |
Output is correct |
43 |
Correct |
112 ms |
776 KB |
Output is correct |
44 |
Correct |
177 ms |
912 KB |
Output is correct |
45 |
Correct |
156 ms |
768 KB |
Output is correct |
46 |
Correct |
308 ms |
800 KB |
Output is correct |
47 |
Correct |
428 ms |
896 KB |
Output is correct |
48 |
Correct |
69 ms |
1024 KB |
Output is correct |
49 |
Correct |
66 ms |
920 KB |
Output is correct |