#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;
joinset(cor[i],cor[{i.fi,i.se+2}]);
pair<int,int> cur={i.fi-1,i.se+1};
if(vis.count(cur)) cur.fi+=2;
if(vis.count(cur)) continue;
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
145 ms |
22732 KB |
Output is correct |
10 |
Correct |
11 ms |
2864 KB |
Output is correct |
11 |
Correct |
90 ms |
12236 KB |
Output is correct |
12 |
Correct |
15 ms |
3932 KB |
Output is correct |
13 |
Correct |
62 ms |
8900 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
600 KB |
Output is correct |
16 |
Correct |
146 ms |
22616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
145 ms |
22732 KB |
Output is correct |
10 |
Correct |
11 ms |
2864 KB |
Output is correct |
11 |
Correct |
90 ms |
12236 KB |
Output is correct |
12 |
Correct |
15 ms |
3932 KB |
Output is correct |
13 |
Correct |
62 ms |
8900 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
600 KB |
Output is correct |
16 |
Correct |
146 ms |
22616 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
432 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 |
333 ms |
47512 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 |
1036 KB |
Output is correct |
28 |
Correct |
113 ms |
19176 KB |
Output is correct |
29 |
Correct |
192 ms |
28596 KB |
Output is correct |
30 |
Correct |
273 ms |
38056 KB |
Output is correct |
31 |
Correct |
344 ms |
47528 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
3 ms |
604 KB |
Output is correct |
44 |
Correct |
3 ms |
860 KB |
Output is correct |
45 |
Correct |
144 ms |
22708 KB |
Output is correct |
46 |
Correct |
215 ms |
32748 KB |
Output is correct |
47 |
Correct |
246 ms |
32932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
145 ms |
22732 KB |
Output is correct |
10 |
Correct |
11 ms |
2864 KB |
Output is correct |
11 |
Correct |
90 ms |
12236 KB |
Output is correct |
12 |
Correct |
15 ms |
3932 KB |
Output is correct |
13 |
Correct |
62 ms |
8900 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
600 KB |
Output is correct |
16 |
Correct |
146 ms |
22616 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
432 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 |
333 ms |
47512 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 |
1036 KB |
Output is correct |
28 |
Correct |
113 ms |
19176 KB |
Output is correct |
29 |
Correct |
192 ms |
28596 KB |
Output is correct |
30 |
Correct |
273 ms |
38056 KB |
Output is correct |
31 |
Correct |
344 ms |
47528 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
3 ms |
604 KB |
Output is correct |
44 |
Correct |
3 ms |
860 KB |
Output is correct |
45 |
Correct |
144 ms |
22708 KB |
Output is correct |
46 |
Correct |
215 ms |
32748 KB |
Output is correct |
47 |
Correct |
246 ms |
32932 KB |
Output is correct |
48 |
Correct |
0 ms |
344 KB |
Output is correct |
49 |
Correct |
1 ms |
344 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
55 |
Correct |
349 ms |
48380 KB |
Output is correct |
56 |
Correct |
1 ms |
344 KB |
Output is correct |
57 |
Correct |
2 ms |
856 KB |
Output is correct |
58 |
Correct |
8 ms |
1884 KB |
Output is correct |
59 |
Correct |
12 ms |
2396 KB |
Output is correct |
60 |
Correct |
145 ms |
24272 KB |
Output is correct |
61 |
Correct |
220 ms |
32680 KB |
Output is correct |
62 |
Correct |
271 ms |
39920 KB |
Output is correct |
63 |
Correct |
343 ms |
48292 KB |
Output is correct |
64 |
Correct |
0 ms |
348 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
0 ms |
348 KB |
Output is correct |
67 |
Correct |
322 ms |
46616 KB |
Output is correct |
68 |
Correct |
320 ms |
47900 KB |
Output is correct |
69 |
Correct |
302 ms |
47268 KB |
Output is correct |
70 |
Correct |
5 ms |
1112 KB |
Output is correct |
71 |
Correct |
9 ms |
1852 KB |
Output is correct |
72 |
Correct |
141 ms |
23404 KB |
Output is correct |
73 |
Correct |
306 ms |
34984 KB |
Output is correct |
74 |
Correct |
389 ms |
46500 KB |
Output is correct |
75 |
Correct |
376 ms |
48276 KB |
Output is correct |
76 |
Correct |
348 ms |
47912 KB |
Output is correct |
77 |
Correct |
6 ms |
1372 KB |
Output is correct |
78 |
Correct |
9 ms |
2144 KB |
Output is correct |
79 |
Correct |
183 ms |
23360 KB |
Output is correct |
80 |
Correct |
258 ms |
35132 KB |
Output is correct |
81 |
Correct |
372 ms |
46760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
145 ms |
22732 KB |
Output is correct |
10 |
Correct |
11 ms |
2864 KB |
Output is correct |
11 |
Correct |
90 ms |
12236 KB |
Output is correct |
12 |
Correct |
15 ms |
3932 KB |
Output is correct |
13 |
Correct |
62 ms |
8900 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
600 KB |
Output is correct |
16 |
Correct |
146 ms |
22616 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
335 ms |
45040 KB |
Output is correct |
21 |
Correct |
341 ms |
45236 KB |
Output is correct |
22 |
Correct |
321 ms |
44896 KB |
Output is correct |
23 |
Correct |
252 ms |
38568 KB |
Output is correct |
24 |
Correct |
115 ms |
26196 KB |
Output is correct |
25 |
Correct |
290 ms |
38708 KB |
Output is correct |
26 |
Correct |
271 ms |
38564 KB |
Output is correct |
27 |
Correct |
315 ms |
44964 KB |
Output is correct |
28 |
Correct |
374 ms |
44964 KB |
Output is correct |
29 |
Correct |
352 ms |
44960 KB |
Output is correct |
30 |
Correct |
446 ms |
44948 KB |
Output is correct |
31 |
Correct |
0 ms |
600 KB |
Output is correct |
32 |
Incorrect |
15 ms |
3160 KB |
Solution announced impossible, but it is possible. |
33 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
145 ms |
22732 KB |
Output is correct |
10 |
Correct |
11 ms |
2864 KB |
Output is correct |
11 |
Correct |
90 ms |
12236 KB |
Output is correct |
12 |
Correct |
15 ms |
3932 KB |
Output is correct |
13 |
Correct |
62 ms |
8900 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
600 KB |
Output is correct |
16 |
Correct |
146 ms |
22616 KB |
Output is correct |
17 |
Correct |
426 ms |
46920 KB |
Output is correct |
18 |
Correct |
373 ms |
46472 KB |
Output is correct |
19 |
Correct |
382 ms |
47144 KB |
Output is correct |
20 |
Correct |
374 ms |
45628 KB |
Output is correct |
21 |
Correct |
313 ms |
40828 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Incorrect |
40 ms |
6608 KB |
Solution announced impossible, but it is possible. |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
145 ms |
22732 KB |
Output is correct |
10 |
Correct |
11 ms |
2864 KB |
Output is correct |
11 |
Correct |
90 ms |
12236 KB |
Output is correct |
12 |
Correct |
15 ms |
3932 KB |
Output is correct |
13 |
Correct |
62 ms |
8900 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
600 KB |
Output is correct |
16 |
Correct |
146 ms |
22616 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
432 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 |
333 ms |
47512 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 |
1036 KB |
Output is correct |
28 |
Correct |
113 ms |
19176 KB |
Output is correct |
29 |
Correct |
192 ms |
28596 KB |
Output is correct |
30 |
Correct |
273 ms |
38056 KB |
Output is correct |
31 |
Correct |
344 ms |
47528 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
3 ms |
604 KB |
Output is correct |
44 |
Correct |
3 ms |
860 KB |
Output is correct |
45 |
Correct |
144 ms |
22708 KB |
Output is correct |
46 |
Correct |
215 ms |
32748 KB |
Output is correct |
47 |
Correct |
246 ms |
32932 KB |
Output is correct |
48 |
Correct |
0 ms |
344 KB |
Output is correct |
49 |
Correct |
1 ms |
344 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
55 |
Correct |
349 ms |
48380 KB |
Output is correct |
56 |
Correct |
1 ms |
344 KB |
Output is correct |
57 |
Correct |
2 ms |
856 KB |
Output is correct |
58 |
Correct |
8 ms |
1884 KB |
Output is correct |
59 |
Correct |
12 ms |
2396 KB |
Output is correct |
60 |
Correct |
145 ms |
24272 KB |
Output is correct |
61 |
Correct |
220 ms |
32680 KB |
Output is correct |
62 |
Correct |
271 ms |
39920 KB |
Output is correct |
63 |
Correct |
343 ms |
48292 KB |
Output is correct |
64 |
Correct |
0 ms |
348 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
0 ms |
348 KB |
Output is correct |
67 |
Correct |
322 ms |
46616 KB |
Output is correct |
68 |
Correct |
320 ms |
47900 KB |
Output is correct |
69 |
Correct |
302 ms |
47268 KB |
Output is correct |
70 |
Correct |
5 ms |
1112 KB |
Output is correct |
71 |
Correct |
9 ms |
1852 KB |
Output is correct |
72 |
Correct |
141 ms |
23404 KB |
Output is correct |
73 |
Correct |
306 ms |
34984 KB |
Output is correct |
74 |
Correct |
389 ms |
46500 KB |
Output is correct |
75 |
Correct |
376 ms |
48276 KB |
Output is correct |
76 |
Correct |
348 ms |
47912 KB |
Output is correct |
77 |
Correct |
6 ms |
1372 KB |
Output is correct |
78 |
Correct |
9 ms |
2144 KB |
Output is correct |
79 |
Correct |
183 ms |
23360 KB |
Output is correct |
80 |
Correct |
258 ms |
35132 KB |
Output is correct |
81 |
Correct |
372 ms |
46760 KB |
Output is correct |
82 |
Correct |
0 ms |
348 KB |
Output is correct |
83 |
Correct |
0 ms |
348 KB |
Output is correct |
84 |
Correct |
1 ms |
348 KB |
Output is correct |
85 |
Correct |
335 ms |
45040 KB |
Output is correct |
86 |
Correct |
341 ms |
45236 KB |
Output is correct |
87 |
Correct |
321 ms |
44896 KB |
Output is correct |
88 |
Correct |
252 ms |
38568 KB |
Output is correct |
89 |
Correct |
115 ms |
26196 KB |
Output is correct |
90 |
Correct |
290 ms |
38708 KB |
Output is correct |
91 |
Correct |
271 ms |
38564 KB |
Output is correct |
92 |
Correct |
315 ms |
44964 KB |
Output is correct |
93 |
Correct |
374 ms |
44964 KB |
Output is correct |
94 |
Correct |
352 ms |
44960 KB |
Output is correct |
95 |
Correct |
446 ms |
44948 KB |
Output is correct |
96 |
Correct |
0 ms |
600 KB |
Output is correct |
97 |
Incorrect |
15 ms |
3160 KB |
Solution announced impossible, but it is possible. |
98 |
Halted |
0 ms |
0 KB |
- |