#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 (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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4952 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
5136 KB |
Output is correct |
9 |
Correct |
138 ms |
37572 KB |
Output is correct |
10 |
Correct |
10 ms |
8304 KB |
Output is correct |
11 |
Correct |
54 ms |
22680 KB |
Output is correct |
12 |
Correct |
17 ms |
10076 KB |
Output is correct |
13 |
Correct |
45 ms |
17352 KB |
Output is correct |
14 |
Correct |
3 ms |
5208 KB |
Output is correct |
15 |
Correct |
3 ms |
5468 KB |
Output is correct |
16 |
Correct |
151 ms |
35000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4952 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
5136 KB |
Output is correct |
9 |
Correct |
138 ms |
37572 KB |
Output is correct |
10 |
Correct |
10 ms |
8304 KB |
Output is correct |
11 |
Correct |
54 ms |
22680 KB |
Output is correct |
12 |
Correct |
17 ms |
10076 KB |
Output is correct |
13 |
Correct |
45 ms |
17352 KB |
Output is correct |
14 |
Correct |
3 ms |
5208 KB |
Output is correct |
15 |
Correct |
3 ms |
5468 KB |
Output is correct |
16 |
Correct |
151 ms |
35000 KB |
Output is correct |
17 |
Correct |
1 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
4920 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
316 ms |
60856 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 |
5724 KB |
Output is correct |
27 |
Correct |
4 ms |
5980 KB |
Output is correct |
28 |
Correct |
93 ms |
27472 KB |
Output is correct |
29 |
Correct |
158 ms |
38040 KB |
Output is correct |
30 |
Correct |
255 ms |
49828 KB |
Output is correct |
31 |
Correct |
367 ms |
60324 KB |
Output is correct |
32 |
Correct |
2 ms |
4956 KB |
Output is correct |
33 |
Correct |
1 ms |
5132 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 |
2 ms |
4956 KB |
Output is correct |
38 |
Correct |
1 ms |
4952 KB |
Output is correct |
39 |
Correct |
2 ms |
4956 KB |
Output is correct |
40 |
Correct |
3 ms |
4956 KB |
Output is correct |
41 |
Correct |
1 ms |
5136 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 |
5720 KB |
Output is correct |
45 |
Correct |
132 ms |
34696 KB |
Output is correct |
46 |
Correct |
244 ms |
48292 KB |
Output is correct |
47 |
Correct |
197 ms |
47872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4952 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
5136 KB |
Output is correct |
9 |
Correct |
138 ms |
37572 KB |
Output is correct |
10 |
Correct |
10 ms |
8304 KB |
Output is correct |
11 |
Correct |
54 ms |
22680 KB |
Output is correct |
12 |
Correct |
17 ms |
10076 KB |
Output is correct |
13 |
Correct |
45 ms |
17352 KB |
Output is correct |
14 |
Correct |
3 ms |
5208 KB |
Output is correct |
15 |
Correct |
3 ms |
5468 KB |
Output is correct |
16 |
Correct |
151 ms |
35000 KB |
Output is correct |
17 |
Correct |
1 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
4920 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
316 ms |
60856 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 |
5724 KB |
Output is correct |
27 |
Correct |
4 ms |
5980 KB |
Output is correct |
28 |
Correct |
93 ms |
27472 KB |
Output is correct |
29 |
Correct |
158 ms |
38040 KB |
Output is correct |
30 |
Correct |
255 ms |
49828 KB |
Output is correct |
31 |
Correct |
367 ms |
60324 KB |
Output is correct |
32 |
Correct |
2 ms |
4956 KB |
Output is correct |
33 |
Correct |
1 ms |
5132 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 |
2 ms |
4956 KB |
Output is correct |
38 |
Correct |
1 ms |
4952 KB |
Output is correct |
39 |
Correct |
2 ms |
4956 KB |
Output is correct |
40 |
Correct |
3 ms |
4956 KB |
Output is correct |
41 |
Correct |
1 ms |
5136 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 |
5720 KB |
Output is correct |
45 |
Correct |
132 ms |
34696 KB |
Output is correct |
46 |
Correct |
244 ms |
48292 KB |
Output is correct |
47 |
Correct |
197 ms |
47872 KB |
Output is correct |
48 |
Correct |
2 ms |
4952 KB |
Output is correct |
49 |
Correct |
1 ms |
4956 KB |
Output is correct |
50 |
Correct |
2 ms |
4952 KB |
Output is correct |
51 |
Correct |
1 ms |
5136 KB |
Output is correct |
52 |
Correct |
1 ms |
4956 KB |
Output is correct |
53 |
Correct |
1 ms |
4956 KB |
Output is correct |
54 |
Correct |
1 ms |
4956 KB |
Output is correct |
55 |
Correct |
388 ms |
69852 KB |
Output is correct |
56 |
Correct |
2 ms |
4956 KB |
Output is correct |
57 |
Correct |
3 ms |
5724 KB |
Output is correct |
58 |
Correct |
8 ms |
7004 KB |
Output is correct |
59 |
Correct |
10 ms |
7432 KB |
Output is correct |
60 |
Correct |
154 ms |
37288 KB |
Output is correct |
61 |
Incorrect |
249 ms |
48728 KB |
Pair u[179991]=33260 @(2, 89994) and v[179991]=119157 @(6, 89994) does not form a valid edge (distance != 2) |
62 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4952 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
5136 KB |
Output is correct |
9 |
Correct |
138 ms |
37572 KB |
Output is correct |
10 |
Correct |
10 ms |
8304 KB |
Output is correct |
11 |
Correct |
54 ms |
22680 KB |
Output is correct |
12 |
Correct |
17 ms |
10076 KB |
Output is correct |
13 |
Correct |
45 ms |
17352 KB |
Output is correct |
14 |
Correct |
3 ms |
5208 KB |
Output is correct |
15 |
Correct |
3 ms |
5468 KB |
Output is correct |
16 |
Correct |
151 ms |
35000 KB |
Output is correct |
17 |
Correct |
2 ms |
4952 KB |
Output is correct |
18 |
Correct |
2 ms |
4952 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Incorrect |
307 ms |
66060 KB |
Tree @(199997, 7) appears more than once: for edges on positions 2 and 100000 |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4952 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
5136 KB |
Output is correct |
9 |
Correct |
138 ms |
37572 KB |
Output is correct |
10 |
Correct |
10 ms |
8304 KB |
Output is correct |
11 |
Correct |
54 ms |
22680 KB |
Output is correct |
12 |
Correct |
17 ms |
10076 KB |
Output is correct |
13 |
Correct |
45 ms |
17352 KB |
Output is correct |
14 |
Correct |
3 ms |
5208 KB |
Output is correct |
15 |
Correct |
3 ms |
5468 KB |
Output is correct |
16 |
Correct |
151 ms |
35000 KB |
Output is correct |
17 |
Incorrect |
302 ms |
63796 KB |
Pair u[100000]=112394 @(2, 4) and v[100000]=87394 @(100002, 4) does not form a valid edge (distance != 2) |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4952 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
5136 KB |
Output is correct |
9 |
Correct |
138 ms |
37572 KB |
Output is correct |
10 |
Correct |
10 ms |
8304 KB |
Output is correct |
11 |
Correct |
54 ms |
22680 KB |
Output is correct |
12 |
Correct |
17 ms |
10076 KB |
Output is correct |
13 |
Correct |
45 ms |
17352 KB |
Output is correct |
14 |
Correct |
3 ms |
5208 KB |
Output is correct |
15 |
Correct |
3 ms |
5468 KB |
Output is correct |
16 |
Correct |
151 ms |
35000 KB |
Output is correct |
17 |
Correct |
1 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
4920 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
316 ms |
60856 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 |
5724 KB |
Output is correct |
27 |
Correct |
4 ms |
5980 KB |
Output is correct |
28 |
Correct |
93 ms |
27472 KB |
Output is correct |
29 |
Correct |
158 ms |
38040 KB |
Output is correct |
30 |
Correct |
255 ms |
49828 KB |
Output is correct |
31 |
Correct |
367 ms |
60324 KB |
Output is correct |
32 |
Correct |
2 ms |
4956 KB |
Output is correct |
33 |
Correct |
1 ms |
5132 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 |
2 ms |
4956 KB |
Output is correct |
38 |
Correct |
1 ms |
4952 KB |
Output is correct |
39 |
Correct |
2 ms |
4956 KB |
Output is correct |
40 |
Correct |
3 ms |
4956 KB |
Output is correct |
41 |
Correct |
1 ms |
5136 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 |
5720 KB |
Output is correct |
45 |
Correct |
132 ms |
34696 KB |
Output is correct |
46 |
Correct |
244 ms |
48292 KB |
Output is correct |
47 |
Correct |
197 ms |
47872 KB |
Output is correct |
48 |
Correct |
2 ms |
4952 KB |
Output is correct |
49 |
Correct |
1 ms |
4956 KB |
Output is correct |
50 |
Correct |
2 ms |
4952 KB |
Output is correct |
51 |
Correct |
1 ms |
5136 KB |
Output is correct |
52 |
Correct |
1 ms |
4956 KB |
Output is correct |
53 |
Correct |
1 ms |
4956 KB |
Output is correct |
54 |
Correct |
1 ms |
4956 KB |
Output is correct |
55 |
Correct |
388 ms |
69852 KB |
Output is correct |
56 |
Correct |
2 ms |
4956 KB |
Output is correct |
57 |
Correct |
3 ms |
5724 KB |
Output is correct |
58 |
Correct |
8 ms |
7004 KB |
Output is correct |
59 |
Correct |
10 ms |
7432 KB |
Output is correct |
60 |
Correct |
154 ms |
37288 KB |
Output is correct |
61 |
Incorrect |
249 ms |
48728 KB |
Pair u[179991]=33260 @(2, 89994) and v[179991]=119157 @(6, 89994) does not form a valid edge (distance != 2) |
62 |
Halted |
0 ms |
0 KB |
- |