#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});
};
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;
}
addedge(id, mp[{curx, cury + 2}], curx - 1, cury + 1);
//if (curx == 2) {
//} 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
124 ms |
36572 KB |
Output is correct |
10 |
Correct |
9 ms |
8300 KB |
Output is correct |
11 |
Correct |
48 ms |
22356 KB |
Output is correct |
12 |
Correct |
13 ms |
9888 KB |
Output is correct |
13 |
Correct |
30 ms |
16904 KB |
Output is correct |
14 |
Correct |
2 ms |
5208 KB |
Output is correct |
15 |
Correct |
2 ms |
5468 KB |
Output is correct |
16 |
Correct |
120 ms |
34304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
124 ms |
36572 KB |
Output is correct |
10 |
Correct |
9 ms |
8300 KB |
Output is correct |
11 |
Correct |
48 ms |
22356 KB |
Output is correct |
12 |
Correct |
13 ms |
9888 KB |
Output is correct |
13 |
Correct |
30 ms |
16904 KB |
Output is correct |
14 |
Correct |
2 ms |
5208 KB |
Output is correct |
15 |
Correct |
2 ms |
5468 KB |
Output is correct |
16 |
Correct |
120 ms |
34304 KB |
Output is correct |
17 |
Correct |
1 ms |
4956 KB |
Output is correct |
18 |
Correct |
1 ms |
4956 KB |
Output is correct |
19 |
Incorrect |
1 ms |
4956 KB |
Tree @(3, 5) appears more than once: for edges on positions 3 and 5 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
124 ms |
36572 KB |
Output is correct |
10 |
Correct |
9 ms |
8300 KB |
Output is correct |
11 |
Correct |
48 ms |
22356 KB |
Output is correct |
12 |
Correct |
13 ms |
9888 KB |
Output is correct |
13 |
Correct |
30 ms |
16904 KB |
Output is correct |
14 |
Correct |
2 ms |
5208 KB |
Output is correct |
15 |
Correct |
2 ms |
5468 KB |
Output is correct |
16 |
Correct |
120 ms |
34304 KB |
Output is correct |
17 |
Correct |
1 ms |
4956 KB |
Output is correct |
18 |
Correct |
1 ms |
4956 KB |
Output is correct |
19 |
Incorrect |
1 ms |
4956 KB |
Tree @(3, 5) appears more than once: for edges on positions 3 and 5 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
124 ms |
36572 KB |
Output is correct |
10 |
Correct |
9 ms |
8300 KB |
Output is correct |
11 |
Correct |
48 ms |
22356 KB |
Output is correct |
12 |
Correct |
13 ms |
9888 KB |
Output is correct |
13 |
Correct |
30 ms |
16904 KB |
Output is correct |
14 |
Correct |
2 ms |
5208 KB |
Output is correct |
15 |
Correct |
2 ms |
5468 KB |
Output is correct |
16 |
Correct |
120 ms |
34304 KB |
Output is correct |
17 |
Correct |
2 ms |
4952 KB |
Output is correct |
18 |
Correct |
1 ms |
4956 KB |
Output is correct |
19 |
Correct |
1 ms |
4956 KB |
Output is correct |
20 |
Correct |
282 ms |
65920 KB |
Output is correct |
21 |
Correct |
277 ms |
64936 KB |
Output is correct |
22 |
Correct |
322 ms |
63656 KB |
Output is correct |
23 |
Correct |
232 ms |
53792 KB |
Output is correct |
24 |
Correct |
181 ms |
29208 KB |
Output is correct |
25 |
Correct |
225 ms |
47780 KB |
Output is correct |
26 |
Correct |
272 ms |
47780 KB |
Output is correct |
27 |
Correct |
307 ms |
54184 KB |
Output is correct |
28 |
Correct |
326 ms |
54184 KB |
Output is correct |
29 |
Correct |
285 ms |
53876 KB |
Output is correct |
30 |
Incorrect |
288 ms |
54128 KB |
Tree @(999, 7) appears more than once: for edges on positions 2 and 1793 |
31 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
124 ms |
36572 KB |
Output is correct |
10 |
Correct |
9 ms |
8300 KB |
Output is correct |
11 |
Correct |
48 ms |
22356 KB |
Output is correct |
12 |
Correct |
13 ms |
9888 KB |
Output is correct |
13 |
Correct |
30 ms |
16904 KB |
Output is correct |
14 |
Correct |
2 ms |
5208 KB |
Output is correct |
15 |
Correct |
2 ms |
5468 KB |
Output is correct |
16 |
Correct |
120 ms |
34304 KB |
Output is correct |
17 |
Correct |
278 ms |
65356 KB |
Output is correct |
18 |
Incorrect |
283 ms |
66312 KB |
Tree @(50001, 50003) appears more than once: for edges on positions 50000 and 149999 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
124 ms |
36572 KB |
Output is correct |
10 |
Correct |
9 ms |
8300 KB |
Output is correct |
11 |
Correct |
48 ms |
22356 KB |
Output is correct |
12 |
Correct |
13 ms |
9888 KB |
Output is correct |
13 |
Correct |
30 ms |
16904 KB |
Output is correct |
14 |
Correct |
2 ms |
5208 KB |
Output is correct |
15 |
Correct |
2 ms |
5468 KB |
Output is correct |
16 |
Correct |
120 ms |
34304 KB |
Output is correct |
17 |
Correct |
1 ms |
4956 KB |
Output is correct |
18 |
Correct |
1 ms |
4956 KB |
Output is correct |
19 |
Incorrect |
1 ms |
4956 KB |
Tree @(3, 5) appears more than once: for edges on positions 3 and 5 |
20 |
Halted |
0 ms |
0 KB |
- |