#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXY = 2e5 + 5;
map<pair<int, int>, int> mp;
vector<pair<int, int>> inY[MAXY];
int construct_roads(vector<int> x, vector<int> y) {
int n = (int) x.size();
for (int i = 0; i < n; ++i) {
inY[y[i]].emplace_back(x[i], i);
mp[{x[i], y[i]}] = i;
}
set<pair<int, int>> se;
vector<int> u, v, a, b;
vector<vector<int>> g(n);
auto addedge = [&](int uu, int vv, int aa, int bb) {
u.push_back(uu);
v.push_back(vv);
a.push_back(aa);
b.push_back(bb);
g[uu].push_back(vv);
g[vv].push_back(uu);
se.insert({aa, bb});
//cout << "u, v, a, b: " << uu << ' ' << vv << ' ' << aa << ' ' << bb << '\n';
};
for (int cury = 2; cury < MAXY; cury += 2) {//add vertical lines
int cnt = 0;
sort(inY[cury].begin(), inY[cury].end());
for (int j = 0; j < (int) inY[cury].size(); ++j) {
auto [curx, id] = inY[cury][j];
if (mp.count({curx, cury + 2})) {
cnt++;
}
}
for (int j = 0; j < (int) inY[cury].size(); ++j) {
auto [curx, id] = inY[cury][j];
if (!mp.count({curx, cury + 2})) {
continue;
}
if (curx == 2) {
addedge(id, mp[{curx, cury + 2}], curx - 1, cury + 1);
} else if (curx == 6) {
addedge(id, mp[{curx, cury + 2}], curx + 1, cury + 1);
} else if (cnt == 1) {
addedge(id, mp[{curx, cury + 2}], curx + (cury % 4 == 0 ? -1 : 1), cury + 1);
}
}
}
for (int cury = 2; cury < MAXY; cury += 2) {//add horizontal lines (x, y) -> (x + 2, y)
for (int j = 0; j < (int) inY[cury].size() - 1; ++j) {
auto [curx, id] = inY[cury][j];
if (inY[cury][j + 1].first - curx > 2) continue;
if (se.count({curx + 1, cury - 1})) {
addedge(id, inY[cury][j + 1].second, curx + 1, cury + 1);
} else {
addedge(id, inY[cury][j + 1].second, curx + 1, cury - 1);
}
}
}
vector<bool> vis(n);
function<void(int)> dfs = [&](int nd) {
vis[nd] = true;
for (int ch : g[nd]) {
if (!vis[ch]) {
dfs(ch);
}
}
};
dfs(0);
for (int i = 0; i < n; ++i) {
if (!vis[i]) {
return 0;
}
}
build(u, v, a, b);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
4 ms |
4956 KB |
Output is correct |
4 |
Correct |
3 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
3 ms |
4952 KB |
Output is correct |
7 |
Correct |
2 ms |
4952 KB |
Output is correct |
8 |
Correct |
2 ms |
4936 KB |
Output is correct |
9 |
Correct |
186 ms |
36536 KB |
Output is correct |
10 |
Correct |
12 ms |
8300 KB |
Output is correct |
11 |
Correct |
54 ms |
22220 KB |
Output is correct |
12 |
Correct |
17 ms |
9816 KB |
Output is correct |
13 |
Correct |
34 ms |
16836 KB |
Output is correct |
14 |
Correct |
2 ms |
5212 KB |
Output is correct |
15 |
Correct |
3 ms |
5464 KB |
Output is correct |
16 |
Correct |
167 ms |
34176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
4 ms |
4956 KB |
Output is correct |
4 |
Correct |
3 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
3 ms |
4952 KB |
Output is correct |
7 |
Correct |
2 ms |
4952 KB |
Output is correct |
8 |
Correct |
2 ms |
4936 KB |
Output is correct |
9 |
Correct |
186 ms |
36536 KB |
Output is correct |
10 |
Correct |
12 ms |
8300 KB |
Output is correct |
11 |
Correct |
54 ms |
22220 KB |
Output is correct |
12 |
Correct |
17 ms |
9816 KB |
Output is correct |
13 |
Correct |
34 ms |
16836 KB |
Output is correct |
14 |
Correct |
2 ms |
5212 KB |
Output is correct |
15 |
Correct |
3 ms |
5464 KB |
Output is correct |
16 |
Correct |
167 ms |
34176 KB |
Output is correct |
17 |
Correct |
2 ms |
4952 KB |
Output is correct |
18 |
Correct |
3 ms |
4956 KB |
Output is correct |
19 |
Correct |
3 ms |
4956 KB |
Output is correct |
20 |
Correct |
1 ms |
4956 KB |
Output is correct |
21 |
Correct |
1 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
380 ms |
59224 KB |
Output is correct |
24 |
Correct |
1 ms |
4952 KB |
Output is correct |
25 |
Correct |
2 ms |
5468 KB |
Output is correct |
26 |
Correct |
3 ms |
5684 KB |
Output is correct |
27 |
Correct |
5 ms |
5980 KB |
Output is correct |
28 |
Correct |
106 ms |
26808 KB |
Output is correct |
29 |
Correct |
160 ms |
37048 KB |
Output is correct |
30 |
Correct |
232 ms |
48568 KB |
Output is correct |
31 |
Correct |
300 ms |
58532 KB |
Output is correct |
32 |
Correct |
2 ms |
4952 KB |
Output is correct |
33 |
Correct |
1 ms |
4956 KB |
Output is correct |
34 |
Correct |
1 ms |
4956 KB |
Output is correct |
35 |
Correct |
1 ms |
4956 KB |
Output is correct |
36 |
Correct |
1 ms |
4956 KB |
Output is correct |
37 |
Correct |
1 ms |
4956 KB |
Output is correct |
38 |
Correct |
1 ms |
4956 KB |
Output is correct |
39 |
Correct |
1 ms |
4956 KB |
Output is correct |
40 |
Correct |
1 ms |
4956 KB |
Output is correct |
41 |
Correct |
1 ms |
4956 KB |
Output is correct |
42 |
Correct |
2 ms |
4956 KB |
Output is correct |
43 |
Correct |
3 ms |
5468 KB |
Output is correct |
44 |
Correct |
4 ms |
5724 KB |
Output is correct |
45 |
Correct |
147 ms |
33672 KB |
Output is correct |
46 |
Correct |
219 ms |
47008 KB |
Output is correct |
47 |
Correct |
214 ms |
46760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
4 ms |
4956 KB |
Output is correct |
4 |
Correct |
3 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
3 ms |
4952 KB |
Output is correct |
7 |
Correct |
2 ms |
4952 KB |
Output is correct |
8 |
Correct |
2 ms |
4936 KB |
Output is correct |
9 |
Correct |
186 ms |
36536 KB |
Output is correct |
10 |
Correct |
12 ms |
8300 KB |
Output is correct |
11 |
Correct |
54 ms |
22220 KB |
Output is correct |
12 |
Correct |
17 ms |
9816 KB |
Output is correct |
13 |
Correct |
34 ms |
16836 KB |
Output is correct |
14 |
Correct |
2 ms |
5212 KB |
Output is correct |
15 |
Correct |
3 ms |
5464 KB |
Output is correct |
16 |
Correct |
167 ms |
34176 KB |
Output is correct |
17 |
Correct |
2 ms |
4952 KB |
Output is correct |
18 |
Correct |
3 ms |
4956 KB |
Output is correct |
19 |
Correct |
3 ms |
4956 KB |
Output is correct |
20 |
Correct |
1 ms |
4956 KB |
Output is correct |
21 |
Correct |
1 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
380 ms |
59224 KB |
Output is correct |
24 |
Correct |
1 ms |
4952 KB |
Output is correct |
25 |
Correct |
2 ms |
5468 KB |
Output is correct |
26 |
Correct |
3 ms |
5684 KB |
Output is correct |
27 |
Correct |
5 ms |
5980 KB |
Output is correct |
28 |
Correct |
106 ms |
26808 KB |
Output is correct |
29 |
Correct |
160 ms |
37048 KB |
Output is correct |
30 |
Correct |
232 ms |
48568 KB |
Output is correct |
31 |
Correct |
300 ms |
58532 KB |
Output is correct |
32 |
Correct |
2 ms |
4952 KB |
Output is correct |
33 |
Correct |
1 ms |
4956 KB |
Output is correct |
34 |
Correct |
1 ms |
4956 KB |
Output is correct |
35 |
Correct |
1 ms |
4956 KB |
Output is correct |
36 |
Correct |
1 ms |
4956 KB |
Output is correct |
37 |
Correct |
1 ms |
4956 KB |
Output is correct |
38 |
Correct |
1 ms |
4956 KB |
Output is correct |
39 |
Correct |
1 ms |
4956 KB |
Output is correct |
40 |
Correct |
1 ms |
4956 KB |
Output is correct |
41 |
Correct |
1 ms |
4956 KB |
Output is correct |
42 |
Correct |
2 ms |
4956 KB |
Output is correct |
43 |
Correct |
3 ms |
5468 KB |
Output is correct |
44 |
Correct |
4 ms |
5724 KB |
Output is correct |
45 |
Correct |
147 ms |
33672 KB |
Output is correct |
46 |
Correct |
219 ms |
47008 KB |
Output is correct |
47 |
Correct |
214 ms |
46760 KB |
Output is correct |
48 |
Correct |
1 ms |
4956 KB |
Output is correct |
49 |
Correct |
1 ms |
4956 KB |
Output is correct |
50 |
Correct |
1 ms |
4956 KB |
Output is correct |
51 |
Correct |
1 ms |
4956 KB |
Output is correct |
52 |
Correct |
1 ms |
4952 KB |
Output is correct |
53 |
Correct |
2 ms |
4952 KB |
Output is correct |
54 |
Correct |
2 ms |
4956 KB |
Output is correct |
55 |
Correct |
459 ms |
68208 KB |
Output is correct |
56 |
Correct |
1 ms |
4956 KB |
Output is correct |
57 |
Correct |
3 ms |
5724 KB |
Output is correct |
58 |
Correct |
8 ms |
7028 KB |
Output is correct |
59 |
Correct |
12 ms |
7512 KB |
Output is correct |
60 |
Correct |
163 ms |
36756 KB |
Output is correct |
61 |
Correct |
259 ms |
47780 KB |
Output is correct |
62 |
Correct |
317 ms |
58532 KB |
Output is correct |
63 |
Correct |
416 ms |
69816 KB |
Output is correct |
64 |
Correct |
1 ms |
4956 KB |
Output is correct |
65 |
Correct |
1 ms |
4956 KB |
Output is correct |
66 |
Correct |
2 ms |
4956 KB |
Output is correct |
67 |
Correct |
318 ms |
64248 KB |
Output is correct |
68 |
Correct |
321 ms |
64424 KB |
Output is correct |
69 |
Correct |
324 ms |
65420 KB |
Output is correct |
70 |
Correct |
6 ms |
5976 KB |
Output is correct |
71 |
Correct |
8 ms |
6744 KB |
Output is correct |
72 |
Correct |
152 ms |
32444 KB |
Output is correct |
73 |
Correct |
238 ms |
47528 KB |
Output is correct |
74 |
Correct |
345 ms |
59748 KB |
Output is correct |
75 |
Correct |
371 ms |
68984 KB |
Output is correct |
76 |
Correct |
315 ms |
67748 KB |
Output is correct |
77 |
Correct |
5 ms |
6232 KB |
Output is correct |
78 |
Correct |
9 ms |
7248 KB |
Output is correct |
79 |
Correct |
142 ms |
33720 KB |
Output is correct |
80 |
Correct |
238 ms |
48476 KB |
Output is correct |
81 |
Correct |
368 ms |
62988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
4 ms |
4956 KB |
Output is correct |
4 |
Correct |
3 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
3 ms |
4952 KB |
Output is correct |
7 |
Correct |
2 ms |
4952 KB |
Output is correct |
8 |
Correct |
2 ms |
4936 KB |
Output is correct |
9 |
Correct |
186 ms |
36536 KB |
Output is correct |
10 |
Correct |
12 ms |
8300 KB |
Output is correct |
11 |
Correct |
54 ms |
22220 KB |
Output is correct |
12 |
Correct |
17 ms |
9816 KB |
Output is correct |
13 |
Correct |
34 ms |
16836 KB |
Output is correct |
14 |
Correct |
2 ms |
5212 KB |
Output is correct |
15 |
Correct |
3 ms |
5464 KB |
Output is correct |
16 |
Correct |
167 ms |
34176 KB |
Output is correct |
17 |
Correct |
1 ms |
4956 KB |
Output is correct |
18 |
Correct |
1 ms |
4956 KB |
Output is correct |
19 |
Correct |
1 ms |
4952 KB |
Output is correct |
20 |
Incorrect |
328 ms |
63460 KB |
Tree @(199997, 7) appears more than once: for edges on positions 2 and 100000 |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
4 ms |
4956 KB |
Output is correct |
4 |
Correct |
3 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
3 ms |
4952 KB |
Output is correct |
7 |
Correct |
2 ms |
4952 KB |
Output is correct |
8 |
Correct |
2 ms |
4936 KB |
Output is correct |
9 |
Correct |
186 ms |
36536 KB |
Output is correct |
10 |
Correct |
12 ms |
8300 KB |
Output is correct |
11 |
Correct |
54 ms |
22220 KB |
Output is correct |
12 |
Correct |
17 ms |
9816 KB |
Output is correct |
13 |
Correct |
34 ms |
16836 KB |
Output is correct |
14 |
Correct |
2 ms |
5212 KB |
Output is correct |
15 |
Correct |
3 ms |
5464 KB |
Output is correct |
16 |
Correct |
167 ms |
34176 KB |
Output is correct |
17 |
Incorrect |
247 ms |
50740 KB |
Solution announced impossible, but it is possible. |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
4 ms |
4956 KB |
Output is correct |
4 |
Correct |
3 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
3 ms |
4952 KB |
Output is correct |
7 |
Correct |
2 ms |
4952 KB |
Output is correct |
8 |
Correct |
2 ms |
4936 KB |
Output is correct |
9 |
Correct |
186 ms |
36536 KB |
Output is correct |
10 |
Correct |
12 ms |
8300 KB |
Output is correct |
11 |
Correct |
54 ms |
22220 KB |
Output is correct |
12 |
Correct |
17 ms |
9816 KB |
Output is correct |
13 |
Correct |
34 ms |
16836 KB |
Output is correct |
14 |
Correct |
2 ms |
5212 KB |
Output is correct |
15 |
Correct |
3 ms |
5464 KB |
Output is correct |
16 |
Correct |
167 ms |
34176 KB |
Output is correct |
17 |
Correct |
2 ms |
4952 KB |
Output is correct |
18 |
Correct |
3 ms |
4956 KB |
Output is correct |
19 |
Correct |
3 ms |
4956 KB |
Output is correct |
20 |
Correct |
1 ms |
4956 KB |
Output is correct |
21 |
Correct |
1 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
380 ms |
59224 KB |
Output is correct |
24 |
Correct |
1 ms |
4952 KB |
Output is correct |
25 |
Correct |
2 ms |
5468 KB |
Output is correct |
26 |
Correct |
3 ms |
5684 KB |
Output is correct |
27 |
Correct |
5 ms |
5980 KB |
Output is correct |
28 |
Correct |
106 ms |
26808 KB |
Output is correct |
29 |
Correct |
160 ms |
37048 KB |
Output is correct |
30 |
Correct |
232 ms |
48568 KB |
Output is correct |
31 |
Correct |
300 ms |
58532 KB |
Output is correct |
32 |
Correct |
2 ms |
4952 KB |
Output is correct |
33 |
Correct |
1 ms |
4956 KB |
Output is correct |
34 |
Correct |
1 ms |
4956 KB |
Output is correct |
35 |
Correct |
1 ms |
4956 KB |
Output is correct |
36 |
Correct |
1 ms |
4956 KB |
Output is correct |
37 |
Correct |
1 ms |
4956 KB |
Output is correct |
38 |
Correct |
1 ms |
4956 KB |
Output is correct |
39 |
Correct |
1 ms |
4956 KB |
Output is correct |
40 |
Correct |
1 ms |
4956 KB |
Output is correct |
41 |
Correct |
1 ms |
4956 KB |
Output is correct |
42 |
Correct |
2 ms |
4956 KB |
Output is correct |
43 |
Correct |
3 ms |
5468 KB |
Output is correct |
44 |
Correct |
4 ms |
5724 KB |
Output is correct |
45 |
Correct |
147 ms |
33672 KB |
Output is correct |
46 |
Correct |
219 ms |
47008 KB |
Output is correct |
47 |
Correct |
214 ms |
46760 KB |
Output is correct |
48 |
Correct |
1 ms |
4956 KB |
Output is correct |
49 |
Correct |
1 ms |
4956 KB |
Output is correct |
50 |
Correct |
1 ms |
4956 KB |
Output is correct |
51 |
Correct |
1 ms |
4956 KB |
Output is correct |
52 |
Correct |
1 ms |
4952 KB |
Output is correct |
53 |
Correct |
2 ms |
4952 KB |
Output is correct |
54 |
Correct |
2 ms |
4956 KB |
Output is correct |
55 |
Correct |
459 ms |
68208 KB |
Output is correct |
56 |
Correct |
1 ms |
4956 KB |
Output is correct |
57 |
Correct |
3 ms |
5724 KB |
Output is correct |
58 |
Correct |
8 ms |
7028 KB |
Output is correct |
59 |
Correct |
12 ms |
7512 KB |
Output is correct |
60 |
Correct |
163 ms |
36756 KB |
Output is correct |
61 |
Correct |
259 ms |
47780 KB |
Output is correct |
62 |
Correct |
317 ms |
58532 KB |
Output is correct |
63 |
Correct |
416 ms |
69816 KB |
Output is correct |
64 |
Correct |
1 ms |
4956 KB |
Output is correct |
65 |
Correct |
1 ms |
4956 KB |
Output is correct |
66 |
Correct |
2 ms |
4956 KB |
Output is correct |
67 |
Correct |
318 ms |
64248 KB |
Output is correct |
68 |
Correct |
321 ms |
64424 KB |
Output is correct |
69 |
Correct |
324 ms |
65420 KB |
Output is correct |
70 |
Correct |
6 ms |
5976 KB |
Output is correct |
71 |
Correct |
8 ms |
6744 KB |
Output is correct |
72 |
Correct |
152 ms |
32444 KB |
Output is correct |
73 |
Correct |
238 ms |
47528 KB |
Output is correct |
74 |
Correct |
345 ms |
59748 KB |
Output is correct |
75 |
Correct |
371 ms |
68984 KB |
Output is correct |
76 |
Correct |
315 ms |
67748 KB |
Output is correct |
77 |
Correct |
5 ms |
6232 KB |
Output is correct |
78 |
Correct |
9 ms |
7248 KB |
Output is correct |
79 |
Correct |
142 ms |
33720 KB |
Output is correct |
80 |
Correct |
238 ms |
48476 KB |
Output is correct |
81 |
Correct |
368 ms |
62988 KB |
Output is correct |
82 |
Correct |
1 ms |
4956 KB |
Output is correct |
83 |
Correct |
1 ms |
4956 KB |
Output is correct |
84 |
Correct |
1 ms |
4952 KB |
Output is correct |
85 |
Incorrect |
328 ms |
63460 KB |
Tree @(199997, 7) appears more than once: for edges on positions 2 and 100000 |
86 |
Halted |
0 ms |
0 KB |
- |