#include "parks.h"
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vii vector<vi>
#define pi pair<int,int>
#define vp vector<pi>
vi d;
vi h;
int parent(int x){
if(d[x]==x)return x;
return d[x]=parent(d[x]);
}
void connect(int a, int b){
a=parent(a);
b=parent(b);
if(h[a]<h[b])swap(a,b);
if(h[a]==h[b])h[a]++;
d[b]=a;
}
int construct_roads(std::vector<int> x, std::vector<int> y) {
//bsmllah
int n=x.size();
d.resize(n);for(int i=0;i<n;i++)d[i]=i;
h.resize(n);
vi u;
vi v;
vi a;
vi b;
map<pi,int>f;
for(int i=0;i<n;i++){
f.insert(make_pair(pi(x[i],y[i]),i));
}
vii k(4, vi(200001,-1));
for(int i=0;i<n;i++){
k[x[i]/2][y[i]]=i;
if(x[i]==4){
continue;
}
auto itr=f.find(pi(x[i],y[i]+2));
if(itr!=f.end()){
u.push_back(i);
v.push_back(itr->second);
a.push_back(x[i]+(x[i]>3?1:-1));
b.push_back(y[i]+1);
connect(i,itr->second);
}
}
if(k[2][2]!=-1){
if(k[1][2]!=-1){
u.push_back(k[1][2]);
v.push_back(k[2][2]);
connect(k[1][2],k[2][2]);
a.push_back(3);
b.push_back(1);
}
if(k[3][2]!=-1){
u.push_back(k[3][2]);
v.push_back(k[2][2]);
connect(k[3][2],k[2][2]);
a.push_back(5);
b.push_back(1);
}
}
for(int i=4;i<200001;i+=2){
if(k[2][i]==-1)continue;
if(k[2][i-2]==-1){
if(k[1][i]!=-1){
u.push_back(k[1][i]);
v.push_back(k[2][i]);
a.push_back(3);
b.push_back(i-1);
connect(k[1][i],k[2][i]);
}
if(k[3][i]!=-1){
u.push_back(k[3][i]);
v.push_back(k[2][i]);
a.push_back(5);
b.push_back(i-1);
connect(k[3][i],k[2][i]);
}
continue;
}
u.push_back(k[2][i]);
v.push_back(k[2][i-2]);
b.push_back(i-1);
if(i%4){
a.push_back(5);
}
else{
a.push_back(3);
}
connect(k[2][i],k[2][i-2]);
if(k[3][i-2]==-1 && k[3][i]!=-1){
u.push_back(k[3][i]);
v.push_back(k[2][i]);
a.push_back(5);
if(i%4){
b.push_back(i+1);
}
else {
b.push_back(i-1);
}
connect(k[3][i],k[2][i]);
}
if(k[1][i-2]==-1 && k[1][i]!=-1){
u.push_back(k[1][i]);
v.push_back(k[2][i]);
a.push_back(3);
if(i%4){
b.push_back(i-1);
}
else {
b.push_back(i+1);
}
connect(k[1][i],k[2][i]);
}
}
for(int i=0;i<n;i++){
if(parent(d[i])!=parent(d[0]))return 0;
}
build(u,v,a,b);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4156 KB |
Output is correct |
3 |
Correct |
2 ms |
4180 KB |
Output is correct |
4 |
Correct |
2 ms |
4180 KB |
Output is correct |
5 |
Correct |
2 ms |
4180 KB |
Output is correct |
6 |
Correct |
2 ms |
4180 KB |
Output is correct |
7 |
Correct |
2 ms |
4180 KB |
Output is correct |
8 |
Correct |
3 ms |
4180 KB |
Output is correct |
9 |
Correct |
97 ms |
17064 KB |
Output is correct |
10 |
Correct |
8 ms |
5076 KB |
Output is correct |
11 |
Correct |
36 ms |
10700 KB |
Output is correct |
12 |
Correct |
11 ms |
5460 KB |
Output is correct |
13 |
Correct |
19 ms |
8516 KB |
Output is correct |
14 |
Correct |
2 ms |
4308 KB |
Output is correct |
15 |
Correct |
3 ms |
4308 KB |
Output is correct |
16 |
Correct |
99 ms |
17008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4156 KB |
Output is correct |
3 |
Correct |
2 ms |
4180 KB |
Output is correct |
4 |
Correct |
2 ms |
4180 KB |
Output is correct |
5 |
Correct |
2 ms |
4180 KB |
Output is correct |
6 |
Correct |
2 ms |
4180 KB |
Output is correct |
7 |
Correct |
2 ms |
4180 KB |
Output is correct |
8 |
Correct |
3 ms |
4180 KB |
Output is correct |
9 |
Correct |
97 ms |
17064 KB |
Output is correct |
10 |
Correct |
8 ms |
5076 KB |
Output is correct |
11 |
Correct |
36 ms |
10700 KB |
Output is correct |
12 |
Correct |
11 ms |
5460 KB |
Output is correct |
13 |
Correct |
19 ms |
8516 KB |
Output is correct |
14 |
Correct |
2 ms |
4308 KB |
Output is correct |
15 |
Correct |
3 ms |
4308 KB |
Output is correct |
16 |
Correct |
99 ms |
17008 KB |
Output is correct |
17 |
Correct |
2 ms |
4180 KB |
Output is correct |
18 |
Correct |
2 ms |
4180 KB |
Output is correct |
19 |
Correct |
2 ms |
4180 KB |
Output is correct |
20 |
Correct |
2 ms |
4180 KB |
Output is correct |
21 |
Correct |
2 ms |
4180 KB |
Output is correct |
22 |
Correct |
2 ms |
4180 KB |
Output is correct |
23 |
Correct |
246 ms |
30524 KB |
Output is correct |
24 |
Correct |
2 ms |
4220 KB |
Output is correct |
25 |
Correct |
3 ms |
4308 KB |
Output is correct |
26 |
Correct |
3 ms |
4436 KB |
Output is correct |
27 |
Correct |
3 ms |
4564 KB |
Output is correct |
28 |
Correct |
70 ms |
15220 KB |
Output is correct |
29 |
Correct |
111 ms |
20472 KB |
Output is correct |
30 |
Correct |
170 ms |
26872 KB |
Output is correct |
31 |
Correct |
239 ms |
32208 KB |
Output is correct |
32 |
Correct |
2 ms |
4180 KB |
Output is correct |
33 |
Correct |
2 ms |
4180 KB |
Output is correct |
34 |
Correct |
2 ms |
4180 KB |
Output is correct |
35 |
Correct |
2 ms |
4144 KB |
Output is correct |
36 |
Correct |
2 ms |
4192 KB |
Output is correct |
37 |
Correct |
2 ms |
4180 KB |
Output is correct |
38 |
Correct |
2 ms |
4180 KB |
Output is correct |
39 |
Correct |
2 ms |
4180 KB |
Output is correct |
40 |
Correct |
2 ms |
4180 KB |
Output is correct |
41 |
Correct |
2 ms |
4180 KB |
Output is correct |
42 |
Correct |
2 ms |
4180 KB |
Output is correct |
43 |
Correct |
3 ms |
4396 KB |
Output is correct |
44 |
Correct |
3 ms |
4436 KB |
Output is correct |
45 |
Correct |
98 ms |
17944 KB |
Output is correct |
46 |
Correct |
152 ms |
24840 KB |
Output is correct |
47 |
Correct |
156 ms |
24764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4156 KB |
Output is correct |
3 |
Correct |
2 ms |
4180 KB |
Output is correct |
4 |
Correct |
2 ms |
4180 KB |
Output is correct |
5 |
Correct |
2 ms |
4180 KB |
Output is correct |
6 |
Correct |
2 ms |
4180 KB |
Output is correct |
7 |
Correct |
2 ms |
4180 KB |
Output is correct |
8 |
Correct |
3 ms |
4180 KB |
Output is correct |
9 |
Correct |
97 ms |
17064 KB |
Output is correct |
10 |
Correct |
8 ms |
5076 KB |
Output is correct |
11 |
Correct |
36 ms |
10700 KB |
Output is correct |
12 |
Correct |
11 ms |
5460 KB |
Output is correct |
13 |
Correct |
19 ms |
8516 KB |
Output is correct |
14 |
Correct |
2 ms |
4308 KB |
Output is correct |
15 |
Correct |
3 ms |
4308 KB |
Output is correct |
16 |
Correct |
99 ms |
17008 KB |
Output is correct |
17 |
Correct |
2 ms |
4180 KB |
Output is correct |
18 |
Correct |
2 ms |
4180 KB |
Output is correct |
19 |
Correct |
2 ms |
4180 KB |
Output is correct |
20 |
Correct |
2 ms |
4180 KB |
Output is correct |
21 |
Correct |
2 ms |
4180 KB |
Output is correct |
22 |
Correct |
2 ms |
4180 KB |
Output is correct |
23 |
Correct |
246 ms |
30524 KB |
Output is correct |
24 |
Correct |
2 ms |
4220 KB |
Output is correct |
25 |
Correct |
3 ms |
4308 KB |
Output is correct |
26 |
Correct |
3 ms |
4436 KB |
Output is correct |
27 |
Correct |
3 ms |
4564 KB |
Output is correct |
28 |
Correct |
70 ms |
15220 KB |
Output is correct |
29 |
Correct |
111 ms |
20472 KB |
Output is correct |
30 |
Correct |
170 ms |
26872 KB |
Output is correct |
31 |
Correct |
239 ms |
32208 KB |
Output is correct |
32 |
Correct |
2 ms |
4180 KB |
Output is correct |
33 |
Correct |
2 ms |
4180 KB |
Output is correct |
34 |
Correct |
2 ms |
4180 KB |
Output is correct |
35 |
Correct |
2 ms |
4144 KB |
Output is correct |
36 |
Correct |
2 ms |
4192 KB |
Output is correct |
37 |
Correct |
2 ms |
4180 KB |
Output is correct |
38 |
Correct |
2 ms |
4180 KB |
Output is correct |
39 |
Correct |
2 ms |
4180 KB |
Output is correct |
40 |
Correct |
2 ms |
4180 KB |
Output is correct |
41 |
Correct |
2 ms |
4180 KB |
Output is correct |
42 |
Correct |
2 ms |
4180 KB |
Output is correct |
43 |
Correct |
3 ms |
4396 KB |
Output is correct |
44 |
Correct |
3 ms |
4436 KB |
Output is correct |
45 |
Correct |
98 ms |
17944 KB |
Output is correct |
46 |
Correct |
152 ms |
24840 KB |
Output is correct |
47 |
Correct |
156 ms |
24764 KB |
Output is correct |
48 |
Correct |
2 ms |
4144 KB |
Output is correct |
49 |
Correct |
2 ms |
4180 KB |
Output is correct |
50 |
Correct |
2 ms |
4180 KB |
Output is correct |
51 |
Correct |
2 ms |
4180 KB |
Output is correct |
52 |
Correct |
2 ms |
4180 KB |
Output is correct |
53 |
Correct |
2 ms |
4180 KB |
Output is correct |
54 |
Correct |
2 ms |
4132 KB |
Output is correct |
55 |
Correct |
297 ms |
32092 KB |
Output is correct |
56 |
Correct |
2 ms |
4180 KB |
Output is correct |
57 |
Correct |
3 ms |
4360 KB |
Output is correct |
58 |
Correct |
6 ms |
4692 KB |
Output is correct |
59 |
Correct |
6 ms |
5044 KB |
Output is correct |
60 |
Correct |
94 ms |
17828 KB |
Output is correct |
61 |
Correct |
155 ms |
23400 KB |
Output is correct |
62 |
Correct |
173 ms |
27524 KB |
Output is correct |
63 |
Correct |
243 ms |
32212 KB |
Output is correct |
64 |
Correct |
2 ms |
4180 KB |
Output is correct |
65 |
Correct |
2 ms |
4180 KB |
Output is correct |
66 |
Correct |
2 ms |
4136 KB |
Output is correct |
67 |
Correct |
264 ms |
32112 KB |
Output is correct |
68 |
Correct |
287 ms |
32184 KB |
Output is correct |
69 |
Correct |
280 ms |
32016 KB |
Output is correct |
70 |
Correct |
3 ms |
4564 KB |
Output is correct |
71 |
Correct |
6 ms |
4908 KB |
Output is correct |
72 |
Correct |
94 ms |
17796 KB |
Output is correct |
73 |
Correct |
161 ms |
25456 KB |
Output is correct |
74 |
Correct |
247 ms |
32124 KB |
Output is correct |
75 |
Correct |
304 ms |
33808 KB |
Output is correct |
76 |
Correct |
269 ms |
32132 KB |
Output is correct |
77 |
Correct |
4 ms |
4692 KB |
Output is correct |
78 |
Correct |
6 ms |
5076 KB |
Output is correct |
79 |
Correct |
100 ms |
18196 KB |
Output is correct |
80 |
Correct |
157 ms |
26136 KB |
Output is correct |
81 |
Correct |
256 ms |
33152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4156 KB |
Output is correct |
3 |
Correct |
2 ms |
4180 KB |
Output is correct |
4 |
Correct |
2 ms |
4180 KB |
Output is correct |
5 |
Correct |
2 ms |
4180 KB |
Output is correct |
6 |
Correct |
2 ms |
4180 KB |
Output is correct |
7 |
Correct |
2 ms |
4180 KB |
Output is correct |
8 |
Correct |
3 ms |
4180 KB |
Output is correct |
9 |
Correct |
97 ms |
17064 KB |
Output is correct |
10 |
Correct |
8 ms |
5076 KB |
Output is correct |
11 |
Correct |
36 ms |
10700 KB |
Output is correct |
12 |
Correct |
11 ms |
5460 KB |
Output is correct |
13 |
Correct |
19 ms |
8516 KB |
Output is correct |
14 |
Correct |
2 ms |
4308 KB |
Output is correct |
15 |
Correct |
3 ms |
4308 KB |
Output is correct |
16 |
Correct |
99 ms |
17008 KB |
Output is correct |
17 |
Runtime error |
6 ms |
6708 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4156 KB |
Output is correct |
3 |
Correct |
2 ms |
4180 KB |
Output is correct |
4 |
Correct |
2 ms |
4180 KB |
Output is correct |
5 |
Correct |
2 ms |
4180 KB |
Output is correct |
6 |
Correct |
2 ms |
4180 KB |
Output is correct |
7 |
Correct |
2 ms |
4180 KB |
Output is correct |
8 |
Correct |
3 ms |
4180 KB |
Output is correct |
9 |
Correct |
97 ms |
17064 KB |
Output is correct |
10 |
Correct |
8 ms |
5076 KB |
Output is correct |
11 |
Correct |
36 ms |
10700 KB |
Output is correct |
12 |
Correct |
11 ms |
5460 KB |
Output is correct |
13 |
Correct |
19 ms |
8516 KB |
Output is correct |
14 |
Correct |
2 ms |
4308 KB |
Output is correct |
15 |
Correct |
3 ms |
4308 KB |
Output is correct |
16 |
Correct |
99 ms |
17008 KB |
Output is correct |
17 |
Runtime error |
131 ms |
41660 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4156 KB |
Output is correct |
3 |
Correct |
2 ms |
4180 KB |
Output is correct |
4 |
Correct |
2 ms |
4180 KB |
Output is correct |
5 |
Correct |
2 ms |
4180 KB |
Output is correct |
6 |
Correct |
2 ms |
4180 KB |
Output is correct |
7 |
Correct |
2 ms |
4180 KB |
Output is correct |
8 |
Correct |
3 ms |
4180 KB |
Output is correct |
9 |
Correct |
97 ms |
17064 KB |
Output is correct |
10 |
Correct |
8 ms |
5076 KB |
Output is correct |
11 |
Correct |
36 ms |
10700 KB |
Output is correct |
12 |
Correct |
11 ms |
5460 KB |
Output is correct |
13 |
Correct |
19 ms |
8516 KB |
Output is correct |
14 |
Correct |
2 ms |
4308 KB |
Output is correct |
15 |
Correct |
3 ms |
4308 KB |
Output is correct |
16 |
Correct |
99 ms |
17008 KB |
Output is correct |
17 |
Correct |
2 ms |
4180 KB |
Output is correct |
18 |
Correct |
2 ms |
4180 KB |
Output is correct |
19 |
Correct |
2 ms |
4180 KB |
Output is correct |
20 |
Correct |
2 ms |
4180 KB |
Output is correct |
21 |
Correct |
2 ms |
4180 KB |
Output is correct |
22 |
Correct |
2 ms |
4180 KB |
Output is correct |
23 |
Correct |
246 ms |
30524 KB |
Output is correct |
24 |
Correct |
2 ms |
4220 KB |
Output is correct |
25 |
Correct |
3 ms |
4308 KB |
Output is correct |
26 |
Correct |
3 ms |
4436 KB |
Output is correct |
27 |
Correct |
3 ms |
4564 KB |
Output is correct |
28 |
Correct |
70 ms |
15220 KB |
Output is correct |
29 |
Correct |
111 ms |
20472 KB |
Output is correct |
30 |
Correct |
170 ms |
26872 KB |
Output is correct |
31 |
Correct |
239 ms |
32208 KB |
Output is correct |
32 |
Correct |
2 ms |
4180 KB |
Output is correct |
33 |
Correct |
2 ms |
4180 KB |
Output is correct |
34 |
Correct |
2 ms |
4180 KB |
Output is correct |
35 |
Correct |
2 ms |
4144 KB |
Output is correct |
36 |
Correct |
2 ms |
4192 KB |
Output is correct |
37 |
Correct |
2 ms |
4180 KB |
Output is correct |
38 |
Correct |
2 ms |
4180 KB |
Output is correct |
39 |
Correct |
2 ms |
4180 KB |
Output is correct |
40 |
Correct |
2 ms |
4180 KB |
Output is correct |
41 |
Correct |
2 ms |
4180 KB |
Output is correct |
42 |
Correct |
2 ms |
4180 KB |
Output is correct |
43 |
Correct |
3 ms |
4396 KB |
Output is correct |
44 |
Correct |
3 ms |
4436 KB |
Output is correct |
45 |
Correct |
98 ms |
17944 KB |
Output is correct |
46 |
Correct |
152 ms |
24840 KB |
Output is correct |
47 |
Correct |
156 ms |
24764 KB |
Output is correct |
48 |
Correct |
2 ms |
4144 KB |
Output is correct |
49 |
Correct |
2 ms |
4180 KB |
Output is correct |
50 |
Correct |
2 ms |
4180 KB |
Output is correct |
51 |
Correct |
2 ms |
4180 KB |
Output is correct |
52 |
Correct |
2 ms |
4180 KB |
Output is correct |
53 |
Correct |
2 ms |
4180 KB |
Output is correct |
54 |
Correct |
2 ms |
4132 KB |
Output is correct |
55 |
Correct |
297 ms |
32092 KB |
Output is correct |
56 |
Correct |
2 ms |
4180 KB |
Output is correct |
57 |
Correct |
3 ms |
4360 KB |
Output is correct |
58 |
Correct |
6 ms |
4692 KB |
Output is correct |
59 |
Correct |
6 ms |
5044 KB |
Output is correct |
60 |
Correct |
94 ms |
17828 KB |
Output is correct |
61 |
Correct |
155 ms |
23400 KB |
Output is correct |
62 |
Correct |
173 ms |
27524 KB |
Output is correct |
63 |
Correct |
243 ms |
32212 KB |
Output is correct |
64 |
Correct |
2 ms |
4180 KB |
Output is correct |
65 |
Correct |
2 ms |
4180 KB |
Output is correct |
66 |
Correct |
2 ms |
4136 KB |
Output is correct |
67 |
Correct |
264 ms |
32112 KB |
Output is correct |
68 |
Correct |
287 ms |
32184 KB |
Output is correct |
69 |
Correct |
280 ms |
32016 KB |
Output is correct |
70 |
Correct |
3 ms |
4564 KB |
Output is correct |
71 |
Correct |
6 ms |
4908 KB |
Output is correct |
72 |
Correct |
94 ms |
17796 KB |
Output is correct |
73 |
Correct |
161 ms |
25456 KB |
Output is correct |
74 |
Correct |
247 ms |
32124 KB |
Output is correct |
75 |
Correct |
304 ms |
33808 KB |
Output is correct |
76 |
Correct |
269 ms |
32132 KB |
Output is correct |
77 |
Correct |
4 ms |
4692 KB |
Output is correct |
78 |
Correct |
6 ms |
5076 KB |
Output is correct |
79 |
Correct |
100 ms |
18196 KB |
Output is correct |
80 |
Correct |
157 ms |
26136 KB |
Output is correct |
81 |
Correct |
256 ms |
33152 KB |
Output is correct |
82 |
Runtime error |
6 ms |
6708 KB |
Execution killed with signal 11 |
83 |
Halted |
0 ms |
0 KB |
- |