#include "parks.h"
#include <iostream>
#include <map>
#include <array>
#include <queue>
#define ll long long
using namespace std;
map <array<ll, 2>, ll> mp;
map <array<ll, 2>, ll> visited;
map <array<ll, 2>, ll> pt;
map <array<ll, 3>, ll> edge;
queue <array<ll, 2>> Q;
vector <int> U, V, A, B;
ll dj[4][2] = {-1, -1, -1, 1, 1, 1, 1, -1}, dk[4][2] = {-2, 0, 0, 2, 2, 0, 0, -2};
void dfs(ll u, ll v) {
++visited[{u, v}];
for (int i=0; i<4; ++i) {
ll nx = u + dk[i][0], ny = v + dk[i][1];
if (pt.count({nx, ny}) && !visited.count({nx, ny})) dfs(nx, ny);
}
}
void solve(ll u, ll v) {
for (int i=0; i<4; ++i) {
if (edge.count({u, v, i})) {
U.push_back(pt[{u + dj[i][0], v + dj[i][1]}]);
V.push_back(pt[{u + dj[(i+1)%4][0], v + dj[(i+1)%4][1]}]);
A.push_back(u);
B.push_back(v);
edge.erase({u, v, i});
edge.erase({u + dk[i][0], v + dk[i][1], i ^ 2});
solve(u + dk[i][0], v + dk[i][1]);
break;
}
}
}
int construct_roads(std::vector<int> x, std::vector<int> y) {
ll n = x.size();
for (int i=0; i<n; ++i) {
pt[{x[i], y[i]}] = i;
for (int j=0; j<4; ++j) {
ll nx = x[i] + dj[j][0], ny = y[i] + dj[j][1];
++mp[{nx, ny}];
}
}
dfs(x[0], y[0]);
if (visited.size() != pt.size()) return 0;
for (auto it = mp.begin(); it != mp.end();) {
auto nx = next(it);
auto [u, v] = it->first;
ll tot = 0;
for (int i=0; i<4; ++i) {
if (pt.count({u + dj[i][0], v + dj[i][1]}) && pt.count({u + dj[(i+1)%4][0], v + dj[(i+1)%4][1]})) {
++tot;
++edge[{u, v, i}];
}
}
mp[{u, v}] = tot;
if (tot == 0) mp.erase(it);
else if (tot == 1) Q.push({u, v});
it = nx;
}
while (!Q.empty()) {
auto [u, v] = Q.front();
Q.pop();
if (!mp.count({u, v})) continue;
for (int i=0; i<4; ++i) {
if (edge.count({u, v, i})) {
U.push_back(pt[{u + dj[i][0], v + dj[i][1]}]);
V.push_back(pt[{u + dj[(i+1)%4][0], v + dj[(i+1)%4][1]}]);
edge.erase({u, v, i});
edge.erase({u + dk[i][0], v + dk[i][1], i ^ 2});
--mp[{u + dk[i][0], v + dk[i][1]}];
if (mp[{u + dk[i][0], v + dk[i][1]}] == 1) Q.push({u + dk[i][0], v + dk[i][1]});
else if (mp[{u + dk[i][0], v + dk[i][1]}] == 0) mp.erase({u + dk[i][0], v + dk[i][1]});
}
}
mp.erase({u, v});
A.push_back(u);
B.push_back(v);
}
for (auto [y, z] : mp) {
if (z == 4) return 0;
}
for (auto [y, z] : mp) {
auto [u, v] = y;
solve(u, v);
}
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 |
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 |
512 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 |
452 ms |
61372 KB |
Output is correct |
10 |
Correct |
33 ms |
6496 KB |
Output is correct |
11 |
Correct |
241 ms |
33756 KB |
Output is correct |
12 |
Correct |
62 ms |
9528 KB |
Output is correct |
13 |
Correct |
66 ms |
15700 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
832 KB |
Output is correct |
16 |
Correct |
429 ms |
55620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
512 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 |
452 ms |
61372 KB |
Output is correct |
10 |
Correct |
33 ms |
6496 KB |
Output is correct |
11 |
Correct |
241 ms |
33756 KB |
Output is correct |
12 |
Correct |
62 ms |
9528 KB |
Output is correct |
13 |
Correct |
66 ms |
15700 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
832 KB |
Output is correct |
16 |
Correct |
429 ms |
55620 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 |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1316 ms |
131512 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
4 ms |
1116 KB |
Output is correct |
26 |
Correct |
4 ms |
1116 KB |
Output is correct |
27 |
Correct |
4 ms |
1208 KB |
Output is correct |
28 |
Correct |
410 ms |
54228 KB |
Output is correct |
29 |
Correct |
676 ms |
81676 KB |
Output is correct |
30 |
Correct |
1012 ms |
111612 KB |
Output is correct |
31 |
Correct |
1341 ms |
128760 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 |
348 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 |
436 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
860 KB |
Output is correct |
44 |
Correct |
3 ms |
1020 KB |
Output is correct |
45 |
Correct |
515 ms |
54800 KB |
Output is correct |
46 |
Correct |
817 ms |
81044 KB |
Output is correct |
47 |
Correct |
735 ms |
79536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
512 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 |
452 ms |
61372 KB |
Output is correct |
10 |
Correct |
33 ms |
6496 KB |
Output is correct |
11 |
Correct |
241 ms |
33756 KB |
Output is correct |
12 |
Correct |
62 ms |
9528 KB |
Output is correct |
13 |
Correct |
66 ms |
15700 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
832 KB |
Output is correct |
16 |
Correct |
429 ms |
55620 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 |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1316 ms |
131512 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
4 ms |
1116 KB |
Output is correct |
26 |
Correct |
4 ms |
1116 KB |
Output is correct |
27 |
Correct |
4 ms |
1208 KB |
Output is correct |
28 |
Correct |
410 ms |
54228 KB |
Output is correct |
29 |
Correct |
676 ms |
81676 KB |
Output is correct |
30 |
Correct |
1012 ms |
111612 KB |
Output is correct |
31 |
Correct |
1341 ms |
128760 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 |
348 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 |
436 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
860 KB |
Output is correct |
44 |
Correct |
3 ms |
1020 KB |
Output is correct |
45 |
Correct |
515 ms |
54800 KB |
Output is correct |
46 |
Correct |
817 ms |
81044 KB |
Output is correct |
47 |
Correct |
735 ms |
79536 KB |
Output is correct |
48 |
Correct |
0 ms |
344 KB |
Output is correct |
49 |
Correct |
0 ms |
348 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 |
Incorrect |
1253 ms |
131972 KB |
Tree @(3, 5) appears more than once: for edges on positions 133335 and 200001 |
56 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
512 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 |
452 ms |
61372 KB |
Output is correct |
10 |
Correct |
33 ms |
6496 KB |
Output is correct |
11 |
Correct |
241 ms |
33756 KB |
Output is correct |
12 |
Correct |
62 ms |
9528 KB |
Output is correct |
13 |
Correct |
66 ms |
15700 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
832 KB |
Output is correct |
16 |
Correct |
429 ms |
55620 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 |
348 KB |
Output is correct |
20 |
Correct |
1041 ms |
120904 KB |
Output is correct |
21 |
Correct |
1051 ms |
115076 KB |
Output is correct |
22 |
Correct |
1077 ms |
111764 KB |
Output is correct |
23 |
Correct |
815 ms |
99512 KB |
Output is correct |
24 |
Correct |
388 ms |
67780 KB |
Output is correct |
25 |
Correct |
341 ms |
42836 KB |
Output is correct |
26 |
Correct |
343 ms |
42832 KB |
Output is correct |
27 |
Correct |
990 ms |
99840 KB |
Output is correct |
28 |
Correct |
901 ms |
99756 KB |
Output is correct |
29 |
Correct |
998 ms |
98304 KB |
Output is correct |
30 |
Correct |
1108 ms |
98640 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
59 ms |
7876 KB |
Output is correct |
33 |
Correct |
139 ms |
28172 KB |
Output is correct |
34 |
Correct |
1018 ms |
116240 KB |
Output is correct |
35 |
Correct |
14 ms |
2652 KB |
Output is correct |
36 |
Correct |
66 ms |
10752 KB |
Output is correct |
37 |
Correct |
153 ms |
20648 KB |
Output is correct |
38 |
Correct |
400 ms |
36420 KB |
Output is correct |
39 |
Correct |
592 ms |
49504 KB |
Output is correct |
40 |
Correct |
808 ms |
63292 KB |
Output is correct |
41 |
Correct |
942 ms |
76488 KB |
Output is correct |
42 |
Correct |
1123 ms |
90948 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
344 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
3 ms |
860 KB |
Output is correct |
55 |
Correct |
3 ms |
1116 KB |
Output is correct |
56 |
Correct |
522 ms |
54740 KB |
Output is correct |
57 |
Correct |
737 ms |
81116 KB |
Output is correct |
58 |
Correct |
806 ms |
79532 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
0 ms |
348 KB |
Output is correct |
62 |
Correct |
1098 ms |
118288 KB |
Output is correct |
63 |
Correct |
1065 ms |
118540 KB |
Output is correct |
64 |
Correct |
965 ms |
120420 KB |
Output is correct |
65 |
Correct |
4 ms |
1372 KB |
Output is correct |
66 |
Correct |
8 ms |
2164 KB |
Output is correct |
67 |
Correct |
491 ms |
50292 KB |
Output is correct |
68 |
Correct |
785 ms |
79324 KB |
Output is correct |
69 |
Correct |
1260 ms |
104472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
512 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 |
452 ms |
61372 KB |
Output is correct |
10 |
Correct |
33 ms |
6496 KB |
Output is correct |
11 |
Correct |
241 ms |
33756 KB |
Output is correct |
12 |
Correct |
62 ms |
9528 KB |
Output is correct |
13 |
Correct |
66 ms |
15700 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
832 KB |
Output is correct |
16 |
Correct |
429 ms |
55620 KB |
Output is correct |
17 |
Correct |
1035 ms |
127044 KB |
Output is correct |
18 |
Correct |
1018 ms |
123788 KB |
Output is correct |
19 |
Correct |
1010 ms |
118912 KB |
Output is correct |
20 |
Correct |
1028 ms |
109240 KB |
Output is correct |
21 |
Correct |
961 ms |
99960 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
138 ms |
16080 KB |
Output is correct |
24 |
Correct |
30 ms |
5460 KB |
Output is correct |
25 |
Correct |
92 ms |
14928 KB |
Output is correct |
26 |
Correct |
176 ms |
24152 KB |
Output is correct |
27 |
Correct |
580 ms |
56420 KB |
Output is correct |
28 |
Correct |
781 ms |
70232 KB |
Output is correct |
29 |
Correct |
920 ms |
84948 KB |
Output is correct |
30 |
Correct |
1175 ms |
98256 KB |
Output is correct |
31 |
Correct |
1601 ms |
112672 KB |
Output is correct |
32 |
Correct |
1289 ms |
121552 KB |
Output is correct |
33 |
Correct |
1053 ms |
126196 KB |
Output is correct |
34 |
Correct |
7 ms |
1728 KB |
Output is correct |
35 |
Correct |
10 ms |
2676 KB |
Output is correct |
36 |
Correct |
532 ms |
54548 KB |
Output is correct |
37 |
Correct |
921 ms |
84096 KB |
Output is correct |
38 |
Correct |
1329 ms |
110832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
512 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 |
452 ms |
61372 KB |
Output is correct |
10 |
Correct |
33 ms |
6496 KB |
Output is correct |
11 |
Correct |
241 ms |
33756 KB |
Output is correct |
12 |
Correct |
62 ms |
9528 KB |
Output is correct |
13 |
Correct |
66 ms |
15700 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
832 KB |
Output is correct |
16 |
Correct |
429 ms |
55620 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 |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1316 ms |
131512 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
4 ms |
1116 KB |
Output is correct |
26 |
Correct |
4 ms |
1116 KB |
Output is correct |
27 |
Correct |
4 ms |
1208 KB |
Output is correct |
28 |
Correct |
410 ms |
54228 KB |
Output is correct |
29 |
Correct |
676 ms |
81676 KB |
Output is correct |
30 |
Correct |
1012 ms |
111612 KB |
Output is correct |
31 |
Correct |
1341 ms |
128760 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 |
348 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 |
436 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
860 KB |
Output is correct |
44 |
Correct |
3 ms |
1020 KB |
Output is correct |
45 |
Correct |
515 ms |
54800 KB |
Output is correct |
46 |
Correct |
817 ms |
81044 KB |
Output is correct |
47 |
Correct |
735 ms |
79536 KB |
Output is correct |
48 |
Correct |
0 ms |
344 KB |
Output is correct |
49 |
Correct |
0 ms |
348 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 |
Incorrect |
1253 ms |
131972 KB |
Tree @(3, 5) appears more than once: for edges on positions 133335 and 200001 |
56 |
Halted |
0 ms |
0 KB |
- |