#include<bits/stdc++.h>
#include "parks.h"
using namespace std;
#define mp make_pair
#define pb push_back
vector<pair<int,int>> G;
vector<pair<int,int>> x_axis[200005];
vector<pair<int,int>> y_axis[200005];
vector<pair<int,int>> choose;
vector<int> u,v,a,b;
int Boss[200005];
int query(int node){
if(Boss[node]==node) return node;
return Boss[node]=query(Boss[node]);
}
int Union(int x,int y){
if(query(x)==query(y)) return 0;
Boss[query(x)]=query(y);
return 1;
}
int construct_roads(vector<int> x,vector<int> y){
for(int i=0;i<200005;i++){
Boss[i]=i;
}
for(int i=0;i<(int)x.size();i++){
x_axis[x[i]].pb(mp(y[i],i));
y_axis[y[i]].pb(mp(x[i],i));
}
for(int i=0;i<200005;i++){
sort(x_axis[i].begin(),x_axis[i].end());
sort(y_axis[i].begin(),y_axis[i].end());
}
//construct graph
for(int i=0;i<200005;i++){
for(int j=0;j<(int)x_axis[i].size()-1;j++){
//cout<<x_axis[i][j+1].first<<"\n";
if(x_axis[i][j+1].first-x_axis[i][j].first==2){
G.pb(mp(x_axis[i][j+1].second,x_axis[i][j].second));
}
}
for(int j=0;j<(int)y_axis[i].size()-1;j++){
if(y_axis[i][j+1].first-y_axis[i][j].first==2){
G.pb(mp(y_axis[i][j+1].second,y_axis[i][j].second));
}
}
}
for(auto i:G){
//cout<<i.first<<" "<<i.second<<"\n";
if(Union(i.first,i.second)){
choose.pb(mp(i.first,i.second));
}
}
for(auto i:choose){
if((x[i.first]+y[i.first])%4) swap(i.first,i.second);
//cout<<x[i.first]<<" "<<y[i.first]<<" "<<x[i.second]<<" "<<y[i.second]<<"\n";
if(x[i.second]-x[i.first]==2){
u.pb(i.first);v.pb(i.second);a.pb(x[i.first]+1);b.pb(y[i.first]-1);
}
if(x[i.second]-x[i.first]==-2){
u.pb(i.first);v.pb(i.second);a.pb(x[i.first]-1);b.pb(y[i.first]+1);
}
if(y[i.second]-y[i.first]==2){
u.pb(i.first);v.pb(i.second);a.pb(x[i.first]+1);b.pb(y[i.first]+1);
}
if(y[i.second]-y[i.first]==-2){
u.pb(i.first);v.pb(i.second);a.pb(x[i.first]-1);b.pb(y[i.first]-1);
}
//cout<<v.back()<<" \n";
}
//for(int i:v) cout<<i<<" ";
if((int)choose.size()==(int)x.size()-1){
build(u,v,a,b);
return 1;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
10452 KB |
Output is correct |
2 |
Correct |
7 ms |
10452 KB |
Output is correct |
3 |
Correct |
8 ms |
10452 KB |
Output is correct |
4 |
Correct |
8 ms |
10464 KB |
Output is correct |
5 |
Correct |
9 ms |
10472 KB |
Output is correct |
6 |
Correct |
9 ms |
10468 KB |
Output is correct |
7 |
Correct |
8 ms |
10452 KB |
Output is correct |
8 |
Correct |
8 ms |
10468 KB |
Output is correct |
9 |
Correct |
83 ms |
24632 KB |
Output is correct |
10 |
Correct |
15 ms |
11988 KB |
Output is correct |
11 |
Correct |
38 ms |
17936 KB |
Output is correct |
12 |
Correct |
16 ms |
12572 KB |
Output is correct |
13 |
Correct |
20 ms |
15216 KB |
Output is correct |
14 |
Correct |
8 ms |
10452 KB |
Output is correct |
15 |
Correct |
9 ms |
10580 KB |
Output is correct |
16 |
Correct |
83 ms |
24648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
10452 KB |
Output is correct |
2 |
Correct |
7 ms |
10452 KB |
Output is correct |
3 |
Correct |
8 ms |
10452 KB |
Output is correct |
4 |
Correct |
8 ms |
10464 KB |
Output is correct |
5 |
Correct |
9 ms |
10472 KB |
Output is correct |
6 |
Correct |
9 ms |
10468 KB |
Output is correct |
7 |
Correct |
8 ms |
10452 KB |
Output is correct |
8 |
Correct |
8 ms |
10468 KB |
Output is correct |
9 |
Correct |
83 ms |
24632 KB |
Output is correct |
10 |
Correct |
15 ms |
11988 KB |
Output is correct |
11 |
Correct |
38 ms |
17936 KB |
Output is correct |
12 |
Correct |
16 ms |
12572 KB |
Output is correct |
13 |
Correct |
20 ms |
15216 KB |
Output is correct |
14 |
Correct |
8 ms |
10452 KB |
Output is correct |
15 |
Correct |
9 ms |
10580 KB |
Output is correct |
16 |
Correct |
83 ms |
24648 KB |
Output is correct |
17 |
Incorrect |
9 ms |
10452 KB |
Tree @(3, 3) appears more than once: for edges on positions 0 and 2 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
10452 KB |
Output is correct |
2 |
Correct |
7 ms |
10452 KB |
Output is correct |
3 |
Correct |
8 ms |
10452 KB |
Output is correct |
4 |
Correct |
8 ms |
10464 KB |
Output is correct |
5 |
Correct |
9 ms |
10472 KB |
Output is correct |
6 |
Correct |
9 ms |
10468 KB |
Output is correct |
7 |
Correct |
8 ms |
10452 KB |
Output is correct |
8 |
Correct |
8 ms |
10468 KB |
Output is correct |
9 |
Correct |
83 ms |
24632 KB |
Output is correct |
10 |
Correct |
15 ms |
11988 KB |
Output is correct |
11 |
Correct |
38 ms |
17936 KB |
Output is correct |
12 |
Correct |
16 ms |
12572 KB |
Output is correct |
13 |
Correct |
20 ms |
15216 KB |
Output is correct |
14 |
Correct |
8 ms |
10452 KB |
Output is correct |
15 |
Correct |
9 ms |
10580 KB |
Output is correct |
16 |
Correct |
83 ms |
24648 KB |
Output is correct |
17 |
Incorrect |
9 ms |
10452 KB |
Tree @(3, 3) appears more than once: for edges on positions 0 and 2 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
10452 KB |
Output is correct |
2 |
Correct |
7 ms |
10452 KB |
Output is correct |
3 |
Correct |
8 ms |
10452 KB |
Output is correct |
4 |
Correct |
8 ms |
10464 KB |
Output is correct |
5 |
Correct |
9 ms |
10472 KB |
Output is correct |
6 |
Correct |
9 ms |
10468 KB |
Output is correct |
7 |
Correct |
8 ms |
10452 KB |
Output is correct |
8 |
Correct |
8 ms |
10468 KB |
Output is correct |
9 |
Correct |
83 ms |
24632 KB |
Output is correct |
10 |
Correct |
15 ms |
11988 KB |
Output is correct |
11 |
Correct |
38 ms |
17936 KB |
Output is correct |
12 |
Correct |
16 ms |
12572 KB |
Output is correct |
13 |
Correct |
20 ms |
15216 KB |
Output is correct |
14 |
Correct |
8 ms |
10452 KB |
Output is correct |
15 |
Correct |
9 ms |
10580 KB |
Output is correct |
16 |
Correct |
83 ms |
24648 KB |
Output is correct |
17 |
Correct |
7 ms |
10452 KB |
Output is correct |
18 |
Correct |
10 ms |
10472 KB |
Output is correct |
19 |
Correct |
8 ms |
10452 KB |
Output is correct |
20 |
Correct |
246 ms |
39176 KB |
Output is correct |
21 |
Correct |
181 ms |
38008 KB |
Output is correct |
22 |
Correct |
214 ms |
37876 KB |
Output is correct |
23 |
Correct |
144 ms |
33636 KB |
Output is correct |
24 |
Correct |
68 ms |
19244 KB |
Output is correct |
25 |
Correct |
79 ms |
27752 KB |
Output is correct |
26 |
Correct |
81 ms |
27712 KB |
Output is correct |
27 |
Correct |
137 ms |
35264 KB |
Output is correct |
28 |
Correct |
146 ms |
35272 KB |
Output is correct |
29 |
Correct |
142 ms |
35224 KB |
Output is correct |
30 |
Correct |
134 ms |
35220 KB |
Output is correct |
31 |
Correct |
7 ms |
10452 KB |
Output is correct |
32 |
Correct |
17 ms |
12420 KB |
Output is correct |
33 |
Correct |
69 ms |
19544 KB |
Output is correct |
34 |
Correct |
227 ms |
39232 KB |
Output is correct |
35 |
Correct |
12 ms |
11504 KB |
Output is correct |
36 |
Correct |
26 ms |
15360 KB |
Output is correct |
37 |
Correct |
53 ms |
20284 KB |
Output is correct |
38 |
Correct |
86 ms |
21796 KB |
Output is correct |
39 |
Correct |
86 ms |
25684 KB |
Output is correct |
40 |
Correct |
112 ms |
30988 KB |
Output is correct |
41 |
Correct |
126 ms |
34696 KB |
Output is correct |
42 |
Correct |
159 ms |
38108 KB |
Output is correct |
43 |
Correct |
9 ms |
10452 KB |
Output is correct |
44 |
Correct |
8 ms |
10468 KB |
Output is correct |
45 |
Correct |
12 ms |
10452 KB |
Output is correct |
46 |
Correct |
10 ms |
10472 KB |
Output is correct |
47 |
Correct |
8 ms |
10460 KB |
Output is correct |
48 |
Correct |
8 ms |
10452 KB |
Output is correct |
49 |
Correct |
8 ms |
10452 KB |
Output is correct |
50 |
Correct |
8 ms |
10424 KB |
Output is correct |
51 |
Correct |
9 ms |
10452 KB |
Output is correct |
52 |
Correct |
9 ms |
10452 KB |
Output is correct |
53 |
Correct |
8 ms |
10452 KB |
Output is correct |
54 |
Correct |
8 ms |
10612 KB |
Output is correct |
55 |
Correct |
9 ms |
10708 KB |
Output is correct |
56 |
Correct |
82 ms |
23724 KB |
Output is correct |
57 |
Correct |
121 ms |
30524 KB |
Output is correct |
58 |
Correct |
121 ms |
30520 KB |
Output is correct |
59 |
Correct |
7 ms |
10364 KB |
Output is correct |
60 |
Correct |
8 ms |
10452 KB |
Output is correct |
61 |
Correct |
7 ms |
10468 KB |
Output is correct |
62 |
Correct |
171 ms |
35888 KB |
Output is correct |
63 |
Correct |
157 ms |
35960 KB |
Output is correct |
64 |
Correct |
181 ms |
35856 KB |
Output is correct |
65 |
Correct |
13 ms |
10776 KB |
Output is correct |
66 |
Correct |
11 ms |
11100 KB |
Output is correct |
67 |
Correct |
78 ms |
23152 KB |
Output is correct |
68 |
Correct |
136 ms |
30616 KB |
Output is correct |
69 |
Correct |
167 ms |
36344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
10452 KB |
Output is correct |
2 |
Correct |
7 ms |
10452 KB |
Output is correct |
3 |
Correct |
8 ms |
10452 KB |
Output is correct |
4 |
Correct |
8 ms |
10464 KB |
Output is correct |
5 |
Correct |
9 ms |
10472 KB |
Output is correct |
6 |
Correct |
9 ms |
10468 KB |
Output is correct |
7 |
Correct |
8 ms |
10452 KB |
Output is correct |
8 |
Correct |
8 ms |
10468 KB |
Output is correct |
9 |
Correct |
83 ms |
24632 KB |
Output is correct |
10 |
Correct |
15 ms |
11988 KB |
Output is correct |
11 |
Correct |
38 ms |
17936 KB |
Output is correct |
12 |
Correct |
16 ms |
12572 KB |
Output is correct |
13 |
Correct |
20 ms |
15216 KB |
Output is correct |
14 |
Correct |
8 ms |
10452 KB |
Output is correct |
15 |
Correct |
9 ms |
10580 KB |
Output is correct |
16 |
Correct |
83 ms |
24648 KB |
Output is correct |
17 |
Correct |
185 ms |
36624 KB |
Output is correct |
18 |
Correct |
179 ms |
37024 KB |
Output is correct |
19 |
Correct |
170 ms |
37816 KB |
Output is correct |
20 |
Correct |
131 ms |
34424 KB |
Output is correct |
21 |
Correct |
118 ms |
33908 KB |
Output is correct |
22 |
Correct |
7 ms |
10448 KB |
Output is correct |
23 |
Correct |
28 ms |
14812 KB |
Output is correct |
24 |
Correct |
14 ms |
12492 KB |
Output is correct |
25 |
Correct |
35 ms |
17788 KB |
Output is correct |
26 |
Correct |
57 ms |
21752 KB |
Output is correct |
27 |
Correct |
74 ms |
24920 KB |
Output is correct |
28 |
Correct |
93 ms |
28092 KB |
Output is correct |
29 |
Correct |
134 ms |
32696 KB |
Output is correct |
30 |
Correct |
127 ms |
35016 KB |
Output is correct |
31 |
Correct |
139 ms |
38220 KB |
Output is correct |
32 |
Correct |
182 ms |
36588 KB |
Output is correct |
33 |
Correct |
166 ms |
35880 KB |
Output is correct |
34 |
Correct |
10 ms |
10964 KB |
Output is correct |
35 |
Correct |
11 ms |
11348 KB |
Output is correct |
36 |
Correct |
80 ms |
23328 KB |
Output is correct |
37 |
Correct |
121 ms |
30900 KB |
Output is correct |
38 |
Correct |
180 ms |
36536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
10452 KB |
Output is correct |
2 |
Correct |
7 ms |
10452 KB |
Output is correct |
3 |
Correct |
8 ms |
10452 KB |
Output is correct |
4 |
Correct |
8 ms |
10464 KB |
Output is correct |
5 |
Correct |
9 ms |
10472 KB |
Output is correct |
6 |
Correct |
9 ms |
10468 KB |
Output is correct |
7 |
Correct |
8 ms |
10452 KB |
Output is correct |
8 |
Correct |
8 ms |
10468 KB |
Output is correct |
9 |
Correct |
83 ms |
24632 KB |
Output is correct |
10 |
Correct |
15 ms |
11988 KB |
Output is correct |
11 |
Correct |
38 ms |
17936 KB |
Output is correct |
12 |
Correct |
16 ms |
12572 KB |
Output is correct |
13 |
Correct |
20 ms |
15216 KB |
Output is correct |
14 |
Correct |
8 ms |
10452 KB |
Output is correct |
15 |
Correct |
9 ms |
10580 KB |
Output is correct |
16 |
Correct |
83 ms |
24648 KB |
Output is correct |
17 |
Incorrect |
9 ms |
10452 KB |
Tree @(3, 3) appears more than once: for edges on positions 0 and 2 |
18 |
Halted |
0 ms |
0 KB |
- |