#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int p[N];
int sz[N];
vector<pair<int, int>> inY[N];
int get(int v) {
return p[v] = (p[v] == v ? v : get(p[v]));
}
void unite(int u, int v) {
u = get(u);
v = get(v);
if (sz[u] > sz[v]) swap(u, v);
p[u] = v;
sz[v] += sz[u];
}
int construct_roads(vector<int> vx, vector<int> vy) {
int n = (int) vx.size();
map<pair<int, int>, int> mp;
for (int i = 0; i < n; ++i) {
p[i] = i;
sz[i] = 1;
mp[{vx[i], vy[i]}] = i;
inY[vy[i]].emplace_back(vx[i], i);
}
for (int y = 2; y < N; y += 2) {
sort(inY[y].begin(), inY[y].end());
}
set<pair<int, int>> se;
vector<int> u, v, a, b;
for (int y = 2; y < N; y += 2) {
for (auto [x, i] : inY[y]) {
if (mp.count({x + 2, y})) {
int id = mp[{x + 2, y}];
if (get(id) != get(i)) {
unite(i, id);
u.push_back(i);
v.push_back(id);
if (!se.count({x + 1, y - 1})) {
se.insert({x + 1, y - 1});
a.push_back(x + 1);
b.push_back(y - 1);
} else {
assert(!se.count({x + 1, y + 1}));
se.insert({x + 1, y + 1});
a.push_back(x + 1);
b.push_back(y + 1);
}
}
}
if (mp.count({x, y + 2})) {
int id = mp[{x, y + 2}];
if (get(id) != get(i)) {
unite(i, id);
u.push_back(i);
v.push_back(id);
if (!se.count({x - 1, y + 1})) {
se.insert({x - 1, y + 1});
a.push_back(x - 1);
b.push_back(y + 1);
} else {
assert(!se.count({x + 1, y + 1}));
se.insert({x + 1, y + 1});
a.push_back(x + 1);
b.push_back(y + 1);
}
}
}
}
}
if (sz[get(0)] != n) {
return 0;
}
build(u, v, a, b);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
3 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 |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
3 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
3 ms |
4952 KB |
Output is correct |
9 |
Correct |
125 ms |
27060 KB |
Output is correct |
10 |
Correct |
10 ms |
7680 KB |
Output is correct |
11 |
Correct |
58 ms |
16832 KB |
Output is correct |
12 |
Correct |
15 ms |
8484 KB |
Output is correct |
13 |
Correct |
37 ms |
13456 KB |
Output is correct |
14 |
Correct |
4 ms |
5208 KB |
Output is correct |
15 |
Correct |
3 ms |
5468 KB |
Output is correct |
16 |
Correct |
131 ms |
27000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
3 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 |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
3 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
3 ms |
4952 KB |
Output is correct |
9 |
Correct |
125 ms |
27060 KB |
Output is correct |
10 |
Correct |
10 ms |
7680 KB |
Output is correct |
11 |
Correct |
58 ms |
16832 KB |
Output is correct |
12 |
Correct |
15 ms |
8484 KB |
Output is correct |
13 |
Correct |
37 ms |
13456 KB |
Output is correct |
14 |
Correct |
4 ms |
5208 KB |
Output is correct |
15 |
Correct |
3 ms |
5468 KB |
Output is correct |
16 |
Correct |
131 ms |
27000 KB |
Output is correct |
17 |
Correct |
3 ms |
4952 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 |
4952 KB |
Output is correct |
21 |
Correct |
3 ms |
5148 KB |
Output is correct |
22 |
Correct |
3 ms |
4932 KB |
Output is correct |
23 |
Correct |
306 ms |
45736 KB |
Output is correct |
24 |
Correct |
3 ms |
4952 KB |
Output is correct |
25 |
Correct |
4 ms |
5212 KB |
Output is correct |
26 |
Correct |
4 ms |
5468 KB |
Output is correct |
27 |
Correct |
6 ms |
5724 KB |
Output is correct |
28 |
Correct |
104 ms |
21380 KB |
Output is correct |
29 |
Correct |
178 ms |
29552 KB |
Output is correct |
30 |
Correct |
225 ms |
37796 KB |
Output is correct |
31 |
Correct |
302 ms |
45808 KB |
Output is correct |
32 |
Correct |
3 ms |
4952 KB |
Output is correct |
33 |
Correct |
2 ms |
4952 KB |
Output is correct |
34 |
Correct |
3 ms |
4956 KB |
Output is correct |
35 |
Correct |
2 ms |
4956 KB |
Output is correct |
36 |
Correct |
3 ms |
4956 KB |
Output is correct |
37 |
Correct |
3 ms |
5100 KB |
Output is correct |
38 |
Correct |
2 ms |
4956 KB |
Output is correct |
39 |
Correct |
2 ms |
4952 KB |
Output is correct |
40 |
Correct |
2 ms |
4956 KB |
Output is correct |
41 |
Correct |
2 ms |
4956 KB |
Output is correct |
42 |
Correct |
2 ms |
4956 KB |
Output is correct |
43 |
Correct |
4 ms |
5468 KB |
Output is correct |
44 |
Correct |
5 ms |
5468 KB |
Output is correct |
45 |
Correct |
129 ms |
26168 KB |
Output is correct |
46 |
Correct |
194 ms |
35356 KB |
Output is correct |
47 |
Correct |
223 ms |
35492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
3 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 |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
3 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
3 ms |
4952 KB |
Output is correct |
9 |
Correct |
125 ms |
27060 KB |
Output is correct |
10 |
Correct |
10 ms |
7680 KB |
Output is correct |
11 |
Correct |
58 ms |
16832 KB |
Output is correct |
12 |
Correct |
15 ms |
8484 KB |
Output is correct |
13 |
Correct |
37 ms |
13456 KB |
Output is correct |
14 |
Correct |
4 ms |
5208 KB |
Output is correct |
15 |
Correct |
3 ms |
5468 KB |
Output is correct |
16 |
Correct |
131 ms |
27000 KB |
Output is correct |
17 |
Correct |
3 ms |
4952 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 |
4952 KB |
Output is correct |
21 |
Correct |
3 ms |
5148 KB |
Output is correct |
22 |
Correct |
3 ms |
4932 KB |
Output is correct |
23 |
Correct |
306 ms |
45736 KB |
Output is correct |
24 |
Correct |
3 ms |
4952 KB |
Output is correct |
25 |
Correct |
4 ms |
5212 KB |
Output is correct |
26 |
Correct |
4 ms |
5468 KB |
Output is correct |
27 |
Correct |
6 ms |
5724 KB |
Output is correct |
28 |
Correct |
104 ms |
21380 KB |
Output is correct |
29 |
Correct |
178 ms |
29552 KB |
Output is correct |
30 |
Correct |
225 ms |
37796 KB |
Output is correct |
31 |
Correct |
302 ms |
45808 KB |
Output is correct |
32 |
Correct |
3 ms |
4952 KB |
Output is correct |
33 |
Correct |
2 ms |
4952 KB |
Output is correct |
34 |
Correct |
3 ms |
4956 KB |
Output is correct |
35 |
Correct |
2 ms |
4956 KB |
Output is correct |
36 |
Correct |
3 ms |
4956 KB |
Output is correct |
37 |
Correct |
3 ms |
5100 KB |
Output is correct |
38 |
Correct |
2 ms |
4956 KB |
Output is correct |
39 |
Correct |
2 ms |
4952 KB |
Output is correct |
40 |
Correct |
2 ms |
4956 KB |
Output is correct |
41 |
Correct |
2 ms |
4956 KB |
Output is correct |
42 |
Correct |
2 ms |
4956 KB |
Output is correct |
43 |
Correct |
4 ms |
5468 KB |
Output is correct |
44 |
Correct |
5 ms |
5468 KB |
Output is correct |
45 |
Correct |
129 ms |
26168 KB |
Output is correct |
46 |
Correct |
194 ms |
35356 KB |
Output is correct |
47 |
Correct |
223 ms |
35492 KB |
Output is correct |
48 |
Correct |
3 ms |
4956 KB |
Output is correct |
49 |
Correct |
2 ms |
4956 KB |
Output is correct |
50 |
Correct |
3 ms |
4952 KB |
Output is correct |
51 |
Correct |
2 ms |
4952 KB |
Output is correct |
52 |
Correct |
3 ms |
4956 KB |
Output is correct |
53 |
Correct |
2 ms |
4956 KB |
Output is correct |
54 |
Correct |
3 ms |
4952 KB |
Output is correct |
55 |
Correct |
320 ms |
47272 KB |
Output is correct |
56 |
Correct |
3 ms |
4956 KB |
Output is correct |
57 |
Correct |
4 ms |
5416 KB |
Output is correct |
58 |
Correct |
8 ms |
6492 KB |
Output is correct |
59 |
Correct |
10 ms |
6744 KB |
Output is correct |
60 |
Correct |
138 ms |
26224 KB |
Output is correct |
61 |
Correct |
187 ms |
33444 KB |
Output is correct |
62 |
Correct |
255 ms |
40100 KB |
Output is correct |
63 |
Correct |
328 ms |
47528 KB |
Output is correct |
64 |
Correct |
3 ms |
4952 KB |
Output is correct |
65 |
Correct |
3 ms |
5140 KB |
Output is correct |
66 |
Correct |
3 ms |
4956 KB |
Output is correct |
67 |
Correct |
298 ms |
45728 KB |
Output is correct |
68 |
Correct |
321 ms |
45776 KB |
Output is correct |
69 |
Correct |
296 ms |
45736 KB |
Output is correct |
70 |
Correct |
5 ms |
5724 KB |
Output is correct |
71 |
Correct |
8 ms |
6492 KB |
Output is correct |
72 |
Correct |
127 ms |
25596 KB |
Output is correct |
73 |
Correct |
207 ms |
36088 KB |
Output is correct |
74 |
Correct |
316 ms |
46248 KB |
Output is correct |
75 |
Correct |
318 ms |
46540 KB |
Output is correct |
76 |
Correct |
300 ms |
45732 KB |
Output is correct |
77 |
Correct |
7 ms |
5976 KB |
Output is correct |
78 |
Correct |
10 ms |
6700 KB |
Output is correct |
79 |
Correct |
136 ms |
25528 KB |
Output is correct |
80 |
Correct |
197 ms |
36004 KB |
Output is correct |
81 |
Correct |
331 ms |
46532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
3 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 |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
3 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
3 ms |
4952 KB |
Output is correct |
9 |
Correct |
125 ms |
27060 KB |
Output is correct |
10 |
Correct |
10 ms |
7680 KB |
Output is correct |
11 |
Correct |
58 ms |
16832 KB |
Output is correct |
12 |
Correct |
15 ms |
8484 KB |
Output is correct |
13 |
Correct |
37 ms |
13456 KB |
Output is correct |
14 |
Correct |
4 ms |
5208 KB |
Output is correct |
15 |
Correct |
3 ms |
5468 KB |
Output is correct |
16 |
Correct |
131 ms |
27000 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 |
301 ms |
46724 KB |
Output is correct |
21 |
Correct |
283 ms |
46760 KB |
Output is correct |
22 |
Correct |
288 ms |
46848 KB |
Output is correct |
23 |
Correct |
220 ms |
39148 KB |
Output is correct |
24 |
Correct |
189 ms |
25940 KB |
Output is correct |
25 |
Correct |
287 ms |
38524 KB |
Output is correct |
26 |
Correct |
316 ms |
38312 KB |
Output is correct |
27 |
Correct |
376 ms |
44712 KB |
Output is correct |
28 |
Correct |
352 ms |
44712 KB |
Output is correct |
29 |
Correct |
315 ms |
44412 KB |
Output is correct |
30 |
Correct |
320 ms |
44396 KB |
Output is correct |
31 |
Correct |
3 ms |
4956 KB |
Output is correct |
32 |
Runtime error |
13 ms |
13088 KB |
Execution killed with signal 6 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
3 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 |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
3 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
3 ms |
4952 KB |
Output is correct |
9 |
Correct |
125 ms |
27060 KB |
Output is correct |
10 |
Correct |
10 ms |
7680 KB |
Output is correct |
11 |
Correct |
58 ms |
16832 KB |
Output is correct |
12 |
Correct |
15 ms |
8484 KB |
Output is correct |
13 |
Correct |
37 ms |
13456 KB |
Output is correct |
14 |
Correct |
4 ms |
5208 KB |
Output is correct |
15 |
Correct |
3 ms |
5468 KB |
Output is correct |
16 |
Correct |
131 ms |
27000 KB |
Output is correct |
17 |
Correct |
300 ms |
45368 KB |
Output is correct |
18 |
Correct |
286 ms |
45624 KB |
Output is correct |
19 |
Correct |
301 ms |
46756 KB |
Output is correct |
20 |
Correct |
351 ms |
43360 KB |
Output is correct |
21 |
Correct |
315 ms |
40436 KB |
Output is correct |
22 |
Correct |
2 ms |
4952 KB |
Output is correct |
23 |
Runtime error |
24 ms |
16792 KB |
Execution killed with signal 6 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
3 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 |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
3 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
3 ms |
4952 KB |
Output is correct |
9 |
Correct |
125 ms |
27060 KB |
Output is correct |
10 |
Correct |
10 ms |
7680 KB |
Output is correct |
11 |
Correct |
58 ms |
16832 KB |
Output is correct |
12 |
Correct |
15 ms |
8484 KB |
Output is correct |
13 |
Correct |
37 ms |
13456 KB |
Output is correct |
14 |
Correct |
4 ms |
5208 KB |
Output is correct |
15 |
Correct |
3 ms |
5468 KB |
Output is correct |
16 |
Correct |
131 ms |
27000 KB |
Output is correct |
17 |
Correct |
3 ms |
4952 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 |
4952 KB |
Output is correct |
21 |
Correct |
3 ms |
5148 KB |
Output is correct |
22 |
Correct |
3 ms |
4932 KB |
Output is correct |
23 |
Correct |
306 ms |
45736 KB |
Output is correct |
24 |
Correct |
3 ms |
4952 KB |
Output is correct |
25 |
Correct |
4 ms |
5212 KB |
Output is correct |
26 |
Correct |
4 ms |
5468 KB |
Output is correct |
27 |
Correct |
6 ms |
5724 KB |
Output is correct |
28 |
Correct |
104 ms |
21380 KB |
Output is correct |
29 |
Correct |
178 ms |
29552 KB |
Output is correct |
30 |
Correct |
225 ms |
37796 KB |
Output is correct |
31 |
Correct |
302 ms |
45808 KB |
Output is correct |
32 |
Correct |
3 ms |
4952 KB |
Output is correct |
33 |
Correct |
2 ms |
4952 KB |
Output is correct |
34 |
Correct |
3 ms |
4956 KB |
Output is correct |
35 |
Correct |
2 ms |
4956 KB |
Output is correct |
36 |
Correct |
3 ms |
4956 KB |
Output is correct |
37 |
Correct |
3 ms |
5100 KB |
Output is correct |
38 |
Correct |
2 ms |
4956 KB |
Output is correct |
39 |
Correct |
2 ms |
4952 KB |
Output is correct |
40 |
Correct |
2 ms |
4956 KB |
Output is correct |
41 |
Correct |
2 ms |
4956 KB |
Output is correct |
42 |
Correct |
2 ms |
4956 KB |
Output is correct |
43 |
Correct |
4 ms |
5468 KB |
Output is correct |
44 |
Correct |
5 ms |
5468 KB |
Output is correct |
45 |
Correct |
129 ms |
26168 KB |
Output is correct |
46 |
Correct |
194 ms |
35356 KB |
Output is correct |
47 |
Correct |
223 ms |
35492 KB |
Output is correct |
48 |
Correct |
3 ms |
4956 KB |
Output is correct |
49 |
Correct |
2 ms |
4956 KB |
Output is correct |
50 |
Correct |
3 ms |
4952 KB |
Output is correct |
51 |
Correct |
2 ms |
4952 KB |
Output is correct |
52 |
Correct |
3 ms |
4956 KB |
Output is correct |
53 |
Correct |
2 ms |
4956 KB |
Output is correct |
54 |
Correct |
3 ms |
4952 KB |
Output is correct |
55 |
Correct |
320 ms |
47272 KB |
Output is correct |
56 |
Correct |
3 ms |
4956 KB |
Output is correct |
57 |
Correct |
4 ms |
5416 KB |
Output is correct |
58 |
Correct |
8 ms |
6492 KB |
Output is correct |
59 |
Correct |
10 ms |
6744 KB |
Output is correct |
60 |
Correct |
138 ms |
26224 KB |
Output is correct |
61 |
Correct |
187 ms |
33444 KB |
Output is correct |
62 |
Correct |
255 ms |
40100 KB |
Output is correct |
63 |
Correct |
328 ms |
47528 KB |
Output is correct |
64 |
Correct |
3 ms |
4952 KB |
Output is correct |
65 |
Correct |
3 ms |
5140 KB |
Output is correct |
66 |
Correct |
3 ms |
4956 KB |
Output is correct |
67 |
Correct |
298 ms |
45728 KB |
Output is correct |
68 |
Correct |
321 ms |
45776 KB |
Output is correct |
69 |
Correct |
296 ms |
45736 KB |
Output is correct |
70 |
Correct |
5 ms |
5724 KB |
Output is correct |
71 |
Correct |
8 ms |
6492 KB |
Output is correct |
72 |
Correct |
127 ms |
25596 KB |
Output is correct |
73 |
Correct |
207 ms |
36088 KB |
Output is correct |
74 |
Correct |
316 ms |
46248 KB |
Output is correct |
75 |
Correct |
318 ms |
46540 KB |
Output is correct |
76 |
Correct |
300 ms |
45732 KB |
Output is correct |
77 |
Correct |
7 ms |
5976 KB |
Output is correct |
78 |
Correct |
10 ms |
6700 KB |
Output is correct |
79 |
Correct |
136 ms |
25528 KB |
Output is correct |
80 |
Correct |
197 ms |
36004 KB |
Output is correct |
81 |
Correct |
331 ms |
46532 KB |
Output is correct |
82 |
Correct |
2 ms |
4952 KB |
Output is correct |
83 |
Correct |
3 ms |
4956 KB |
Output is correct |
84 |
Correct |
3 ms |
4956 KB |
Output is correct |
85 |
Correct |
301 ms |
46724 KB |
Output is correct |
86 |
Correct |
283 ms |
46760 KB |
Output is correct |
87 |
Correct |
288 ms |
46848 KB |
Output is correct |
88 |
Correct |
220 ms |
39148 KB |
Output is correct |
89 |
Correct |
189 ms |
25940 KB |
Output is correct |
90 |
Correct |
287 ms |
38524 KB |
Output is correct |
91 |
Correct |
316 ms |
38312 KB |
Output is correct |
92 |
Correct |
376 ms |
44712 KB |
Output is correct |
93 |
Correct |
352 ms |
44712 KB |
Output is correct |
94 |
Correct |
315 ms |
44412 KB |
Output is correct |
95 |
Correct |
320 ms |
44396 KB |
Output is correct |
96 |
Correct |
3 ms |
4956 KB |
Output is correct |
97 |
Runtime error |
13 ms |
13088 KB |
Execution killed with signal 6 |
98 |
Halted |
0 ms |
0 KB |
- |