#include <bits/stdc++.h>
using namespace std;
#include "parks.h"
#define pb push_back
#define fi first
#define se second
const int nax=2e5+5;
set<pair<int,int>> mp;
map<pair<int,int>,int> cor;
set<pair<int,int>> vis;
int parent[nax];
bool check(pair<int,int> a){
if(!mp.count({a.fi-2,a.se})&&!mp.count({a.fi+2,a.se})&&!mp.count({a.fi,a.se-2})&&!mp.count({a.fi,a.se+2})) return false;
return true;
}
int find(int x){
if(x==parent[x]) return x;
return parent[x]=find(parent[x]);
}
bool sameset(int x,int y){
return find(x)==find(y);
}
void joinset(int x,int y) {
x=find(x);
y=find(y);
parent[x]=y;
}
int construct_roads(std::vector<int> x, std::vector<int> y) {
if (x.size() == 1) {
build({}, {}, {}, {});
return 1;
}
std::vector<int> u, v, a, b;
int n=y.size();
for (int i = 0; i < n; ++i) parent[i]=i;
for (int i = 0; i < n; ++i)
{
mp.insert({x[i],y[i]});
cor[{x[i],y[i]}]=i;
}
bool test=true;
for(auto i:mp){
if(!check(i)){
test=false;
break;
}
if(mp.count({i.fi+2,i.se})){
if(sameset(cor[i],cor[{i.fi+2,i.se}])) continue;
pair<int,int> cur={i.fi+1,i.se-1};
if(vis.count(cur)) cur.se+=2;
if(vis.count(cur)) continue;
vis.insert(cur);
joinset(cor[i],cor[{i.fi+2,i.se}]);
a.pb(cur.fi);
b.pb(cur.se);
u.pb(cor[i]);
v.pb(cor[{i.fi+2,i.se}]);
}
if(mp.count({i.fi,i.se+2})){
if(sameset(cor[i],cor[{i.fi,i.se+2}])) continue;
pair<int,int> cur={i.fi-1,i.se+1};
if(vis.count(cur)) cur.fi+=2;
if(vis.count(cur)) continue;
joinset(cor[i],cor[{i.fi,i.se+2}]);
vis.insert(cur);
a.pb(cur.fi);
b.pb(cur.se);
u.pb(cor[i]);
v.pb(cor[{i.fi,i.se+2}]);
}
}
if(!test) return 0;
if((int)u.size()!=n-1) return 0;
build(u, v, a, b);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
444 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
444 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
141 ms |
23284 KB |
Output is correct |
10 |
Correct |
10 ms |
2908 KB |
Output is correct |
11 |
Correct |
74 ms |
12744 KB |
Output is correct |
12 |
Correct |
15 ms |
4188 KB |
Output is correct |
13 |
Correct |
47 ms |
9184 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
138 ms |
23404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
444 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
444 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
141 ms |
23284 KB |
Output is correct |
10 |
Correct |
10 ms |
2908 KB |
Output is correct |
11 |
Correct |
74 ms |
12744 KB |
Output is correct |
12 |
Correct |
15 ms |
4188 KB |
Output is correct |
13 |
Correct |
47 ms |
9184 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
138 ms |
23404 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
355 ms |
48552 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
3 ms |
860 KB |
Output is correct |
27 |
Correct |
4 ms |
1116 KB |
Output is correct |
28 |
Correct |
114 ms |
19776 KB |
Output is correct |
29 |
Correct |
211 ms |
29512 KB |
Output is correct |
30 |
Correct |
267 ms |
39076 KB |
Output is correct |
31 |
Correct |
353 ms |
48692 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
448 KB |
Output is correct |
37 |
Correct |
0 ms |
448 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
604 KB |
Output is correct |
44 |
Correct |
3 ms |
1008 KB |
Output is correct |
45 |
Correct |
141 ms |
23376 KB |
Output is correct |
46 |
Correct |
211 ms |
33540 KB |
Output is correct |
47 |
Correct |
206 ms |
33444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
444 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
444 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
141 ms |
23284 KB |
Output is correct |
10 |
Correct |
10 ms |
2908 KB |
Output is correct |
11 |
Correct |
74 ms |
12744 KB |
Output is correct |
12 |
Correct |
15 ms |
4188 KB |
Output is correct |
13 |
Correct |
47 ms |
9184 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
138 ms |
23404 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
355 ms |
48552 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
3 ms |
860 KB |
Output is correct |
27 |
Correct |
4 ms |
1116 KB |
Output is correct |
28 |
Correct |
114 ms |
19776 KB |
Output is correct |
29 |
Correct |
211 ms |
29512 KB |
Output is correct |
30 |
Correct |
267 ms |
39076 KB |
Output is correct |
31 |
Correct |
353 ms |
48692 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
448 KB |
Output is correct |
37 |
Correct |
0 ms |
448 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
604 KB |
Output is correct |
44 |
Correct |
3 ms |
1008 KB |
Output is correct |
45 |
Correct |
141 ms |
23376 KB |
Output is correct |
46 |
Correct |
211 ms |
33540 KB |
Output is correct |
47 |
Correct |
206 ms |
33444 KB |
Output is correct |
48 |
Correct |
1 ms |
344 KB |
Output is correct |
49 |
Correct |
0 ms |
344 KB |
Output is correct |
50 |
Correct |
0 ms |
344 KB |
Output is correct |
51 |
Correct |
0 ms |
444 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
344 KB |
Output is correct |
55 |
Correct |
356 ms |
47852 KB |
Output is correct |
56 |
Correct |
1 ms |
508 KB |
Output is correct |
57 |
Correct |
3 ms |
856 KB |
Output is correct |
58 |
Correct |
9 ms |
1880 KB |
Output is correct |
59 |
Correct |
12 ms |
2368 KB |
Output is correct |
60 |
Correct |
148 ms |
24004 KB |
Output is correct |
61 |
Correct |
217 ms |
32508 KB |
Output is correct |
62 |
Correct |
264 ms |
39588 KB |
Output is correct |
63 |
Correct |
354 ms |
47780 KB |
Output is correct |
64 |
Correct |
1 ms |
348 KB |
Output is correct |
65 |
Correct |
0 ms |
344 KB |
Output is correct |
66 |
Correct |
0 ms |
348 KB |
Output is correct |
67 |
Correct |
329 ms |
45992 KB |
Output is correct |
68 |
Correct |
314 ms |
47268 KB |
Output is correct |
69 |
Correct |
325 ms |
46504 KB |
Output is correct |
70 |
Correct |
4 ms |
1112 KB |
Output is correct |
71 |
Correct |
9 ms |
1884 KB |
Output is correct |
72 |
Correct |
144 ms |
23360 KB |
Output is correct |
73 |
Correct |
236 ms |
34476 KB |
Output is correct |
74 |
Correct |
341 ms |
46024 KB |
Output is correct |
75 |
Correct |
358 ms |
47528 KB |
Output is correct |
76 |
Correct |
324 ms |
47396 KB |
Output is correct |
77 |
Correct |
5 ms |
1372 KB |
Output is correct |
78 |
Correct |
10 ms |
2140 KB |
Output is correct |
79 |
Correct |
146 ms |
23560 KB |
Output is correct |
80 |
Correct |
238 ms |
34724 KB |
Output is correct |
81 |
Correct |
338 ms |
46060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
444 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
444 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
141 ms |
23284 KB |
Output is correct |
10 |
Correct |
10 ms |
2908 KB |
Output is correct |
11 |
Correct |
74 ms |
12744 KB |
Output is correct |
12 |
Correct |
15 ms |
4188 KB |
Output is correct |
13 |
Correct |
47 ms |
9184 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
138 ms |
23404 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
341 ms |
46384 KB |
Output is correct |
21 |
Correct |
344 ms |
46244 KB |
Output is correct |
22 |
Correct |
337 ms |
46180 KB |
Output is correct |
23 |
Correct |
271 ms |
39596 KB |
Output is correct |
24 |
Correct |
145 ms |
27216 KB |
Output is correct |
25 |
Correct |
337 ms |
39796 KB |
Output is correct |
26 |
Correct |
300 ms |
39620 KB |
Output is correct |
27 |
Correct |
375 ms |
45992 KB |
Output is correct |
28 |
Correct |
318 ms |
45924 KB |
Output is correct |
29 |
Correct |
334 ms |
46056 KB |
Output is correct |
30 |
Correct |
332 ms |
45104 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Incorrect |
15 ms |
3112 KB |
Solution announced impossible, but it is possible. |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
444 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
444 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
141 ms |
23284 KB |
Output is correct |
10 |
Correct |
10 ms |
2908 KB |
Output is correct |
11 |
Correct |
74 ms |
12744 KB |
Output is correct |
12 |
Correct |
15 ms |
4188 KB |
Output is correct |
13 |
Correct |
47 ms |
9184 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
138 ms |
23404 KB |
Output is correct |
17 |
Correct |
312 ms |
45736 KB |
Output is correct |
18 |
Correct |
320 ms |
45224 KB |
Output is correct |
19 |
Correct |
344 ms |
44848 KB |
Output is correct |
20 |
Correct |
309 ms |
44196 KB |
Output is correct |
21 |
Correct |
271 ms |
39592 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Incorrect |
34 ms |
6296 KB |
Solution announced impossible, but it is possible. |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
444 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
444 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
141 ms |
23284 KB |
Output is correct |
10 |
Correct |
10 ms |
2908 KB |
Output is correct |
11 |
Correct |
74 ms |
12744 KB |
Output is correct |
12 |
Correct |
15 ms |
4188 KB |
Output is correct |
13 |
Correct |
47 ms |
9184 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
138 ms |
23404 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
355 ms |
48552 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
3 ms |
860 KB |
Output is correct |
27 |
Correct |
4 ms |
1116 KB |
Output is correct |
28 |
Correct |
114 ms |
19776 KB |
Output is correct |
29 |
Correct |
211 ms |
29512 KB |
Output is correct |
30 |
Correct |
267 ms |
39076 KB |
Output is correct |
31 |
Correct |
353 ms |
48692 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
448 KB |
Output is correct |
37 |
Correct |
0 ms |
448 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
604 KB |
Output is correct |
44 |
Correct |
3 ms |
1008 KB |
Output is correct |
45 |
Correct |
141 ms |
23376 KB |
Output is correct |
46 |
Correct |
211 ms |
33540 KB |
Output is correct |
47 |
Correct |
206 ms |
33444 KB |
Output is correct |
48 |
Correct |
1 ms |
344 KB |
Output is correct |
49 |
Correct |
0 ms |
344 KB |
Output is correct |
50 |
Correct |
0 ms |
344 KB |
Output is correct |
51 |
Correct |
0 ms |
444 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
344 KB |
Output is correct |
55 |
Correct |
356 ms |
47852 KB |
Output is correct |
56 |
Correct |
1 ms |
508 KB |
Output is correct |
57 |
Correct |
3 ms |
856 KB |
Output is correct |
58 |
Correct |
9 ms |
1880 KB |
Output is correct |
59 |
Correct |
12 ms |
2368 KB |
Output is correct |
60 |
Correct |
148 ms |
24004 KB |
Output is correct |
61 |
Correct |
217 ms |
32508 KB |
Output is correct |
62 |
Correct |
264 ms |
39588 KB |
Output is correct |
63 |
Correct |
354 ms |
47780 KB |
Output is correct |
64 |
Correct |
1 ms |
348 KB |
Output is correct |
65 |
Correct |
0 ms |
344 KB |
Output is correct |
66 |
Correct |
0 ms |
348 KB |
Output is correct |
67 |
Correct |
329 ms |
45992 KB |
Output is correct |
68 |
Correct |
314 ms |
47268 KB |
Output is correct |
69 |
Correct |
325 ms |
46504 KB |
Output is correct |
70 |
Correct |
4 ms |
1112 KB |
Output is correct |
71 |
Correct |
9 ms |
1884 KB |
Output is correct |
72 |
Correct |
144 ms |
23360 KB |
Output is correct |
73 |
Correct |
236 ms |
34476 KB |
Output is correct |
74 |
Correct |
341 ms |
46024 KB |
Output is correct |
75 |
Correct |
358 ms |
47528 KB |
Output is correct |
76 |
Correct |
324 ms |
47396 KB |
Output is correct |
77 |
Correct |
5 ms |
1372 KB |
Output is correct |
78 |
Correct |
10 ms |
2140 KB |
Output is correct |
79 |
Correct |
146 ms |
23560 KB |
Output is correct |
80 |
Correct |
238 ms |
34724 KB |
Output is correct |
81 |
Correct |
338 ms |
46060 KB |
Output is correct |
82 |
Correct |
0 ms |
348 KB |
Output is correct |
83 |
Correct |
0 ms |
348 KB |
Output is correct |
84 |
Correct |
0 ms |
348 KB |
Output is correct |
85 |
Correct |
341 ms |
46384 KB |
Output is correct |
86 |
Correct |
344 ms |
46244 KB |
Output is correct |
87 |
Correct |
337 ms |
46180 KB |
Output is correct |
88 |
Correct |
271 ms |
39596 KB |
Output is correct |
89 |
Correct |
145 ms |
27216 KB |
Output is correct |
90 |
Correct |
337 ms |
39796 KB |
Output is correct |
91 |
Correct |
300 ms |
39620 KB |
Output is correct |
92 |
Correct |
375 ms |
45992 KB |
Output is correct |
93 |
Correct |
318 ms |
45924 KB |
Output is correct |
94 |
Correct |
334 ms |
46056 KB |
Output is correct |
95 |
Correct |
332 ms |
45104 KB |
Output is correct |
96 |
Correct |
0 ms |
344 KB |
Output is correct |
97 |
Incorrect |
15 ms |
3112 KB |
Solution announced impossible, but it is possible. |
98 |
Halted |
0 ms |
0 KB |
- |