#include <bits/stdc++.h>
#include "parks.h"
using namespace std;
void build(vector<int>u, vector<int>v, vector<int>a, vector<int>b);
int construct_roads(std::vector<int> xx, std::vector<int> yy) {
const int n = (int)xx.size();
set<pair<int,int>>s;
set<pair<int,int>>t;
map<pair<int,int>,int>id;
for(int i = 0 ; i < n ; i++)
s.insert({xx[i], yy[i]}), id[{xx[i], yy[i]}] = i;
int F,S;
for(int i = 0 ; i < n ; i++) {
if(!s.count({xx[i]-2, yy[i]}))
F = xx[i], S = yy[i];
}
queue<pair<pair<int,int>, int>>st;
st.push({{F, S}, 0});
s.erase(s.find({F, S}));
vector<int>u,v,a,b;
auto process = [&] (int X, int Y, int T) -> void {
s.erase(s.find({X,Y}));
u.push_back(id[{X,Y}]);
st.push({{X, Y}, T});
if(T == 0) {
v.push_back(id[{X-2,Y}]);
if(!t.count({X-1, Y+1}))
t.insert({X-1, Y+1}), a.push_back(X-1), b.push_back(Y+1);
else
t.insert({X-1, Y-1}), a.push_back(X-1), b.push_back(Y-1);
} else if(T == 1) {
v.push_back(id[{X,Y+2}]);
if(!t.count({X+1, Y+1}))
t.insert({X+1, Y+1}), a.push_back(X+1), b.push_back(Y+1);
else
t.insert({X-1, Y+1}), a.push_back(X-1), b.push_back(Y+1);
} else if(T == 2) {
v.push_back(id[{X+2,Y}]);
if(!t.count({X+1, Y-1}))
t.insert({X+1, Y-1}), a.push_back(X+1), b.push_back(Y-1);
else
t.insert({X+1, Y+1}), a.push_back(X+1), b.push_back(Y+1);
} else {
v.push_back(id[{X,Y-2}]);
if(!t.count({X-1, Y-1}))
t.insert({X-1, Y-1}), a.push_back(X-1), b.push_back(Y-1);
else
t.insert({X+1, Y-1}), a.push_back(X+1), b.push_back(Y-1);
}
};
int cnt = 0;
while(!st.empty()) {
auto [x,y] = st.front().first;
int d = st.front().second;
st.pop();
cnt++;
if(d == 0) {
if(s.count({x, y+2})) {
process(x, y+2, 3);
if(s.count({x+2, y}))
process(x+2, y, 0);
if(s.count({x, y-2}))
process(x, y-2, 1);
} else {
if(s.count({x, y-2}))
process(x, y-2, 1);
if(s.count({x+2, y}))
process(x+2, y, 0);
}
} else if(d == 1) {
if(s.count({x+2, y})) {
process(x+2, y, 0);
if(s.count({x, y-2}))
process(x, y-2, 1);
if(s.count({x-2, y}))
process(x-2, y, 2);
} else {
if(s.count({x-2, y}))
process(x-2, y, 2);
if(s.count({x, y-2}))
process(x, y-2, 1);
}
} else if(d == 2) {
if(s.count({x, y-2})) {
process(x, y-2, 1);
if(s.count({x-2, y}))
process(x-2, y, 2);
if(s.count({x, y+2}))
process(x, y+2, 3);
} else {
if(s.count({x, y+2}))
process(x, y+2, 3);
if(s.count({x-2, y}))
process(x-2, y, 2);
}
} else {
if(s.count({x-2, y})) {
process(x-2, y, 2);
if(s.count({x, y+2}))
process(x, y+2, 3);
if(s.count({x+2, y}))
process(x+2, y, 0);
} else {
if(s.count({x+2, y}))
process(x+2, y, 0);
if(s.count({x, y+2}))
process(x, y+2, 3);
}
}
}
if(cnt < n)
return 0;
build(u,v,a,b);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
201 ms |
17664 KB |
Output is correct |
10 |
Correct |
13 ms |
2260 KB |
Output is correct |
11 |
Correct |
83 ms |
9620 KB |
Output is correct |
12 |
Correct |
24 ms |
3112 KB |
Output is correct |
13 |
Correct |
44 ms |
6184 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
230 ms |
17668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
201 ms |
17664 KB |
Output is correct |
10 |
Correct |
13 ms |
2260 KB |
Output is correct |
11 |
Correct |
83 ms |
9620 KB |
Output is correct |
12 |
Correct |
24 ms |
3112 KB |
Output is correct |
13 |
Correct |
44 ms |
6184 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
230 ms |
17668 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
607 ms |
34948 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
3 ms |
724 KB |
Output is correct |
27 |
Correct |
5 ms |
852 KB |
Output is correct |
28 |
Correct |
181 ms |
14800 KB |
Output is correct |
29 |
Correct |
321 ms |
22096 KB |
Output is correct |
30 |
Correct |
481 ms |
29316 KB |
Output is correct |
31 |
Correct |
637 ms |
36484 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
300 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
3 ms |
576 KB |
Output is correct |
44 |
Correct |
4 ms |
596 KB |
Output is correct |
45 |
Correct |
233 ms |
18424 KB |
Output is correct |
46 |
Correct |
368 ms |
26560 KB |
Output is correct |
47 |
Correct |
461 ms |
26560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
201 ms |
17664 KB |
Output is correct |
10 |
Correct |
13 ms |
2260 KB |
Output is correct |
11 |
Correct |
83 ms |
9620 KB |
Output is correct |
12 |
Correct |
24 ms |
3112 KB |
Output is correct |
13 |
Correct |
44 ms |
6184 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
230 ms |
17668 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
607 ms |
34948 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
3 ms |
724 KB |
Output is correct |
27 |
Correct |
5 ms |
852 KB |
Output is correct |
28 |
Correct |
181 ms |
14800 KB |
Output is correct |
29 |
Correct |
321 ms |
22096 KB |
Output is correct |
30 |
Correct |
481 ms |
29316 KB |
Output is correct |
31 |
Correct |
637 ms |
36484 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
300 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
3 ms |
576 KB |
Output is correct |
44 |
Correct |
4 ms |
596 KB |
Output is correct |
45 |
Correct |
233 ms |
18424 KB |
Output is correct |
46 |
Correct |
368 ms |
26560 KB |
Output is correct |
47 |
Correct |
461 ms |
26560 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
244 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
296 KB |
Output is correct |
54 |
Correct |
1 ms |
304 KB |
Output is correct |
55 |
Incorrect |
618 ms |
36620 KB |
Tree @(5, 112389) appears more than once: for edges on positions 6 and 9 |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
201 ms |
17664 KB |
Output is correct |
10 |
Correct |
13 ms |
2260 KB |
Output is correct |
11 |
Correct |
83 ms |
9620 KB |
Output is correct |
12 |
Correct |
24 ms |
3112 KB |
Output is correct |
13 |
Correct |
44 ms |
6184 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
230 ms |
17668 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
692 ms |
37380 KB |
Output is correct |
21 |
Correct |
713 ms |
37144 KB |
Output is correct |
22 |
Correct |
684 ms |
37200 KB |
Output is correct |
23 |
Correct |
509 ms |
31468 KB |
Output is correct |
24 |
Correct |
369 ms |
26944 KB |
Output is correct |
25 |
Correct |
387 ms |
27072 KB |
Output is correct |
26 |
Correct |
330 ms |
27108 KB |
Output is correct |
27 |
Correct |
813 ms |
36640 KB |
Output is correct |
28 |
Correct |
714 ms |
36468 KB |
Output is correct |
29 |
Correct |
893 ms |
36420 KB |
Output is correct |
30 |
Correct |
959 ms |
36548 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
30 ms |
3196 KB |
Output is correct |
33 |
Correct |
138 ms |
14024 KB |
Output is correct |
34 |
Correct |
612 ms |
37360 KB |
Output is correct |
35 |
Correct |
16 ms |
1840 KB |
Output is correct |
36 |
Correct |
63 ms |
7484 KB |
Output is correct |
37 |
Correct |
187 ms |
14316 KB |
Output is correct |
38 |
Correct |
304 ms |
15380 KB |
Output is correct |
39 |
Correct |
383 ms |
20736 KB |
Output is correct |
40 |
Correct |
588 ms |
26292 KB |
Output is correct |
41 |
Correct |
716 ms |
31884 KB |
Output is correct |
42 |
Correct |
936 ms |
37436 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
1 ms |
300 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
3 ms |
468 KB |
Output is correct |
55 |
Correct |
3 ms |
692 KB |
Output is correct |
56 |
Correct |
293 ms |
18464 KB |
Output is correct |
57 |
Correct |
422 ms |
26600 KB |
Output is correct |
58 |
Correct |
470 ms |
26540 KB |
Output is correct |
59 |
Correct |
1 ms |
300 KB |
Output is correct |
60 |
Correct |
1 ms |
212 KB |
Output is correct |
61 |
Correct |
1 ms |
212 KB |
Output is correct |
62 |
Correct |
490 ms |
36472 KB |
Output is correct |
63 |
Correct |
506 ms |
36556 KB |
Output is correct |
64 |
Correct |
540 ms |
36428 KB |
Output is correct |
65 |
Correct |
4 ms |
852 KB |
Output is correct |
66 |
Correct |
10 ms |
1308 KB |
Output is correct |
67 |
Correct |
254 ms |
18404 KB |
Output is correct |
68 |
Correct |
417 ms |
27532 KB |
Output is correct |
69 |
Correct |
609 ms |
36504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
201 ms |
17664 KB |
Output is correct |
10 |
Correct |
13 ms |
2260 KB |
Output is correct |
11 |
Correct |
83 ms |
9620 KB |
Output is correct |
12 |
Correct |
24 ms |
3112 KB |
Output is correct |
13 |
Correct |
44 ms |
6184 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
230 ms |
17668 KB |
Output is correct |
17 |
Correct |
612 ms |
34900 KB |
Output is correct |
18 |
Correct |
638 ms |
36976 KB |
Output is correct |
19 |
Correct |
727 ms |
37156 KB |
Output is correct |
20 |
Correct |
800 ms |
35744 KB |
Output is correct |
21 |
Correct |
697 ms |
32048 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
69 ms |
6508 KB |
Output is correct |
24 |
Correct |
28 ms |
3256 KB |
Output is correct |
25 |
Correct |
137 ms |
10328 KB |
Output is correct |
26 |
Correct |
226 ms |
17072 KB |
Output is correct |
27 |
Correct |
348 ms |
18912 KB |
Output is correct |
28 |
Correct |
501 ms |
23720 KB |
Output is correct |
29 |
Correct |
626 ms |
28276 KB |
Output is correct |
30 |
Correct |
812 ms |
32588 KB |
Output is correct |
31 |
Correct |
874 ms |
37388 KB |
Output is correct |
32 |
Correct |
601 ms |
36504 KB |
Output is correct |
33 |
Correct |
529 ms |
36444 KB |
Output is correct |
34 |
Correct |
5 ms |
1016 KB |
Output is correct |
35 |
Correct |
9 ms |
1588 KB |
Output is correct |
36 |
Correct |
285 ms |
18320 KB |
Output is correct |
37 |
Correct |
449 ms |
27704 KB |
Output is correct |
38 |
Correct |
651 ms |
36664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
201 ms |
17664 KB |
Output is correct |
10 |
Correct |
13 ms |
2260 KB |
Output is correct |
11 |
Correct |
83 ms |
9620 KB |
Output is correct |
12 |
Correct |
24 ms |
3112 KB |
Output is correct |
13 |
Correct |
44 ms |
6184 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
230 ms |
17668 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
607 ms |
34948 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
3 ms |
724 KB |
Output is correct |
27 |
Correct |
5 ms |
852 KB |
Output is correct |
28 |
Correct |
181 ms |
14800 KB |
Output is correct |
29 |
Correct |
321 ms |
22096 KB |
Output is correct |
30 |
Correct |
481 ms |
29316 KB |
Output is correct |
31 |
Correct |
637 ms |
36484 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
300 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
3 ms |
576 KB |
Output is correct |
44 |
Correct |
4 ms |
596 KB |
Output is correct |
45 |
Correct |
233 ms |
18424 KB |
Output is correct |
46 |
Correct |
368 ms |
26560 KB |
Output is correct |
47 |
Correct |
461 ms |
26560 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
244 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
296 KB |
Output is correct |
54 |
Correct |
1 ms |
304 KB |
Output is correct |
55 |
Incorrect |
618 ms |
36620 KB |
Tree @(5, 112389) appears more than once: for edges on positions 6 and 9 |
56 |
Halted |
0 ms |
0 KB |
- |