#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct dsu {
int n;
vector<int> p, s;
dsu(int n) : n(n), p(n), s(n, 1) {
iota(p.begin(), p.end(), 0);
}
int find(int x) {
return x == p[x] ? x : p[x] = find(p[x]);
}
int size(int x) {
return s[find(x)];
}
bool same(int x, int y) {
return find(x) == find(y);
}
bool unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y) {
return 0;
}
if (s[x] > s[y]) {
swap(x, y);
}
p[x] = y;
s[y] += s[x];
return 1;
}
};
constexpr int A = 200000;
int construct_roads(vector<int> X, vector<int> Y) {
int N = X.size();
vector f(7, vector(A + 3, -1));
for (int i = 0; i < N; i++) {
f[X[i]][Y[i]] = i;
}
dsu uf(N);
vector<int> u, v, a, b, m(A + 1, -1), l(A + 1, -1), r(A + 1, -1);
for (int y = 2; y <= A; y += 2) {
for (int x = 2; x <= 6; x += 2) {
if (f[x][y] != -1 && f[x][y + 2] != -1) {
if (x == 4) {
m[y + 1] = u.size();
}
u.push_back(f[x][y]);
v.push_back(f[x][y + 2]);
a.push_back(x == 2 ? 1 : 7);
b.push_back(y + 1);
uf.unite(f[x][y], f[x][y + 2]);
}
if (x != 6 && f[x][y] != -1 && f[x + 2][y] != -1) {
if (x == 2 && l[y - 2] == -1) {
l[y] = u.size();
u.push_back(f[x][y]);
v.push_back(f[x + 2][y]);
a.push_back(3);
b.push_back(-1);
uf.unite(f[x][y], f[x + 2][y]);
}
if (x == 4 && r[y - 2] == -1) {
r[y] = u.size();
u.push_back(f[x][y]);
v.push_back(f[x + 2][y]);
a.push_back(5);
b.push_back(-1);
uf.unite(f[x][y], f[x + 2][y]);
}
}
}
}
if (uf.size(0) != N) {
return 0;
}
vector<int> q(A, -1), s(A, -1), t(A, -1);
for (int i = 1; i <= A; i++) {
if (i % 2 == 1 && m[i] != -1) {
if (s[i - 1] != 1) {
a[m[i]] = 3;
q[i] = 0;
} else {
assert(t[i - 1] != 1);
a[m[i]] = 5;
q[i] = 1;
}
}
if (i % 2 == 0) {
if (l[i] != -1) {
if (q[i - 1] == 0) {
b[l[i]] = i + 1;
s[i] = 1;
} else {
b[l[i]] = i - 1;
s[i] = 0;
}
}
if (r[i] != -1) {
if (q[i - 1] == 1) {
b[r[i]] = i + 1;
t[i] = 1;
} else {
b[r[i]] = i - 1;
t[i] = 0;
}
}
}
}
build(u, v, a, b);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
10436 KB |
Output is correct |
2 |
Correct |
6 ms |
10436 KB |
Output is correct |
3 |
Correct |
4 ms |
8132 KB |
Output is correct |
4 |
Correct |
5 ms |
10496 KB |
Output is correct |
5 |
Correct |
5 ms |
10384 KB |
Output is correct |
6 |
Correct |
4 ms |
8132 KB |
Output is correct |
7 |
Correct |
3 ms |
8132 KB |
Output is correct |
8 |
Correct |
4 ms |
8132 KB |
Output is correct |
9 |
Correct |
48 ms |
17852 KB |
Output is correct |
10 |
Correct |
8 ms |
11204 KB |
Output is correct |
11 |
Correct |
30 ms |
14416 KB |
Output is correct |
12 |
Correct |
11 ms |
11580 KB |
Output is correct |
13 |
Correct |
10 ms |
10436 KB |
Output is correct |
14 |
Correct |
4 ms |
8132 KB |
Output is correct |
15 |
Correct |
4 ms |
8132 KB |
Output is correct |
16 |
Correct |
44 ms |
17840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
10436 KB |
Output is correct |
2 |
Correct |
6 ms |
10436 KB |
Output is correct |
3 |
Correct |
4 ms |
8132 KB |
Output is correct |
4 |
Correct |
5 ms |
10496 KB |
Output is correct |
5 |
Correct |
5 ms |
10384 KB |
Output is correct |
6 |
Correct |
4 ms |
8132 KB |
Output is correct |
7 |
Correct |
3 ms |
8132 KB |
Output is correct |
8 |
Correct |
4 ms |
8132 KB |
Output is correct |
9 |
Correct |
48 ms |
17852 KB |
Output is correct |
10 |
Correct |
8 ms |
11204 KB |
Output is correct |
11 |
Correct |
30 ms |
14416 KB |
Output is correct |
12 |
Correct |
11 ms |
11580 KB |
Output is correct |
13 |
Correct |
10 ms |
10436 KB |
Output is correct |
14 |
Correct |
4 ms |
8132 KB |
Output is correct |
15 |
Correct |
4 ms |
8132 KB |
Output is correct |
16 |
Correct |
44 ms |
17840 KB |
Output is correct |
17 |
Correct |
5 ms |
10396 KB |
Output is correct |
18 |
Correct |
5 ms |
10436 KB |
Output is correct |
19 |
Correct |
5 ms |
10436 KB |
Output is correct |
20 |
Correct |
5 ms |
10436 KB |
Output is correct |
21 |
Correct |
5 ms |
8132 KB |
Output is correct |
22 |
Correct |
5 ms |
10436 KB |
Output is correct |
23 |
Correct |
98 ms |
27156 KB |
Output is correct |
24 |
Correct |
5 ms |
10436 KB |
Output is correct |
25 |
Correct |
5 ms |
10564 KB |
Output is correct |
26 |
Correct |
4 ms |
8260 KB |
Output is correct |
27 |
Correct |
4 ms |
8388 KB |
Output is correct |
28 |
Correct |
40 ms |
17440 KB |
Output is correct |
29 |
Correct |
74 ms |
20956 KB |
Output is correct |
30 |
Correct |
79 ms |
24060 KB |
Output is correct |
31 |
Correct |
99 ms |
27196 KB |
Output is correct |
32 |
Correct |
4 ms |
10436 KB |
Output is correct |
33 |
Correct |
6 ms |
10436 KB |
Output is correct |
34 |
Correct |
6 ms |
10436 KB |
Output is correct |
35 |
Correct |
3 ms |
8132 KB |
Output is correct |
36 |
Correct |
4 ms |
8132 KB |
Output is correct |
37 |
Correct |
5 ms |
10436 KB |
Output is correct |
38 |
Correct |
5 ms |
10436 KB |
Output is correct |
39 |
Correct |
4 ms |
10436 KB |
Output is correct |
40 |
Correct |
4 ms |
10436 KB |
Output is correct |
41 |
Correct |
4 ms |
8132 KB |
Output is correct |
42 |
Correct |
4 ms |
10492 KB |
Output is correct |
43 |
Correct |
4 ms |
8132 KB |
Output is correct |
44 |
Correct |
4 ms |
8260 KB |
Output is correct |
45 |
Correct |
44 ms |
17844 KB |
Output is correct |
46 |
Correct |
63 ms |
21388 KB |
Output is correct |
47 |
Correct |
69 ms |
21388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
10436 KB |
Output is correct |
2 |
Correct |
6 ms |
10436 KB |
Output is correct |
3 |
Correct |
4 ms |
8132 KB |
Output is correct |
4 |
Correct |
5 ms |
10496 KB |
Output is correct |
5 |
Correct |
5 ms |
10384 KB |
Output is correct |
6 |
Correct |
4 ms |
8132 KB |
Output is correct |
7 |
Correct |
3 ms |
8132 KB |
Output is correct |
8 |
Correct |
4 ms |
8132 KB |
Output is correct |
9 |
Correct |
48 ms |
17852 KB |
Output is correct |
10 |
Correct |
8 ms |
11204 KB |
Output is correct |
11 |
Correct |
30 ms |
14416 KB |
Output is correct |
12 |
Correct |
11 ms |
11580 KB |
Output is correct |
13 |
Correct |
10 ms |
10436 KB |
Output is correct |
14 |
Correct |
4 ms |
8132 KB |
Output is correct |
15 |
Correct |
4 ms |
8132 KB |
Output is correct |
16 |
Correct |
44 ms |
17840 KB |
Output is correct |
17 |
Correct |
5 ms |
10396 KB |
Output is correct |
18 |
Correct |
5 ms |
10436 KB |
Output is correct |
19 |
Correct |
5 ms |
10436 KB |
Output is correct |
20 |
Correct |
5 ms |
10436 KB |
Output is correct |
21 |
Correct |
5 ms |
8132 KB |
Output is correct |
22 |
Correct |
5 ms |
10436 KB |
Output is correct |
23 |
Correct |
98 ms |
27156 KB |
Output is correct |
24 |
Correct |
5 ms |
10436 KB |
Output is correct |
25 |
Correct |
5 ms |
10564 KB |
Output is correct |
26 |
Correct |
4 ms |
8260 KB |
Output is correct |
27 |
Correct |
4 ms |
8388 KB |
Output is correct |
28 |
Correct |
40 ms |
17440 KB |
Output is correct |
29 |
Correct |
74 ms |
20956 KB |
Output is correct |
30 |
Correct |
79 ms |
24060 KB |
Output is correct |
31 |
Correct |
99 ms |
27196 KB |
Output is correct |
32 |
Correct |
4 ms |
10436 KB |
Output is correct |
33 |
Correct |
6 ms |
10436 KB |
Output is correct |
34 |
Correct |
6 ms |
10436 KB |
Output is correct |
35 |
Correct |
3 ms |
8132 KB |
Output is correct |
36 |
Correct |
4 ms |
8132 KB |
Output is correct |
37 |
Correct |
5 ms |
10436 KB |
Output is correct |
38 |
Correct |
5 ms |
10436 KB |
Output is correct |
39 |
Correct |
4 ms |
10436 KB |
Output is correct |
40 |
Correct |
4 ms |
10436 KB |
Output is correct |
41 |
Correct |
4 ms |
8132 KB |
Output is correct |
42 |
Correct |
4 ms |
10492 KB |
Output is correct |
43 |
Correct |
4 ms |
8132 KB |
Output is correct |
44 |
Correct |
4 ms |
8260 KB |
Output is correct |
45 |
Correct |
44 ms |
17844 KB |
Output is correct |
46 |
Correct |
63 ms |
21388 KB |
Output is correct |
47 |
Correct |
69 ms |
21388 KB |
Output is correct |
48 |
Correct |
7 ms |
10436 KB |
Output is correct |
49 |
Correct |
5 ms |
10436 KB |
Output is correct |
50 |
Correct |
5 ms |
10436 KB |
Output is correct |
51 |
Correct |
5 ms |
10392 KB |
Output is correct |
52 |
Correct |
5 ms |
10436 KB |
Output is correct |
53 |
Correct |
5 ms |
10436 KB |
Output is correct |
54 |
Correct |
7 ms |
10396 KB |
Output is correct |
55 |
Correct |
104 ms |
29324 KB |
Output is correct |
56 |
Correct |
5 ms |
10436 KB |
Output is correct |
57 |
Correct |
6 ms |
10692 KB |
Output is correct |
58 |
Correct |
8 ms |
11052 KB |
Output is correct |
59 |
Correct |
6 ms |
8772 KB |
Output is correct |
60 |
Correct |
52 ms |
20540 KB |
Output is correct |
61 |
Correct |
70 ms |
23636 KB |
Output is correct |
62 |
Correct |
85 ms |
26464 KB |
Output is correct |
63 |
Correct |
106 ms |
29416 KB |
Output is correct |
64 |
Correct |
4 ms |
8132 KB |
Output is correct |
65 |
Correct |
6 ms |
10392 KB |
Output is correct |
66 |
Correct |
4 ms |
8132 KB |
Output is correct |
67 |
Correct |
84 ms |
26664 KB |
Output is correct |
68 |
Correct |
91 ms |
26664 KB |
Output is correct |
69 |
Correct |
84 ms |
26536 KB |
Output is correct |
70 |
Correct |
4 ms |
8260 KB |
Output is correct |
71 |
Correct |
5 ms |
8516 KB |
Output is correct |
72 |
Correct |
43 ms |
18592 KB |
Output is correct |
73 |
Correct |
65 ms |
22976 KB |
Output is correct |
74 |
Correct |
99 ms |
26676 KB |
Output is correct |
75 |
Correct |
95 ms |
28344 KB |
Output is correct |
76 |
Correct |
84 ms |
26640 KB |
Output is correct |
77 |
Correct |
4 ms |
8388 KB |
Output is correct |
78 |
Correct |
5 ms |
8644 KB |
Output is correct |
79 |
Correct |
48 ms |
18976 KB |
Output is correct |
80 |
Correct |
68 ms |
23728 KB |
Output is correct |
81 |
Correct |
95 ms |
27644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
10436 KB |
Output is correct |
2 |
Correct |
6 ms |
10436 KB |
Output is correct |
3 |
Correct |
4 ms |
8132 KB |
Output is correct |
4 |
Correct |
5 ms |
10496 KB |
Output is correct |
5 |
Correct |
5 ms |
10384 KB |
Output is correct |
6 |
Correct |
4 ms |
8132 KB |
Output is correct |
7 |
Correct |
3 ms |
8132 KB |
Output is correct |
8 |
Correct |
4 ms |
8132 KB |
Output is correct |
9 |
Correct |
48 ms |
17852 KB |
Output is correct |
10 |
Correct |
8 ms |
11204 KB |
Output is correct |
11 |
Correct |
30 ms |
14416 KB |
Output is correct |
12 |
Correct |
11 ms |
11580 KB |
Output is correct |
13 |
Correct |
10 ms |
10436 KB |
Output is correct |
14 |
Correct |
4 ms |
8132 KB |
Output is correct |
15 |
Correct |
4 ms |
8132 KB |
Output is correct |
16 |
Correct |
44 ms |
17840 KB |
Output is correct |
17 |
Runtime error |
7 ms |
11460 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
10436 KB |
Output is correct |
2 |
Correct |
6 ms |
10436 KB |
Output is correct |
3 |
Correct |
4 ms |
8132 KB |
Output is correct |
4 |
Correct |
5 ms |
10496 KB |
Output is correct |
5 |
Correct |
5 ms |
10384 KB |
Output is correct |
6 |
Correct |
4 ms |
8132 KB |
Output is correct |
7 |
Correct |
3 ms |
8132 KB |
Output is correct |
8 |
Correct |
4 ms |
8132 KB |
Output is correct |
9 |
Correct |
48 ms |
17852 KB |
Output is correct |
10 |
Correct |
8 ms |
11204 KB |
Output is correct |
11 |
Correct |
30 ms |
14416 KB |
Output is correct |
12 |
Correct |
11 ms |
11580 KB |
Output is correct |
13 |
Correct |
10 ms |
10436 KB |
Output is correct |
14 |
Correct |
4 ms |
8132 KB |
Output is correct |
15 |
Correct |
4 ms |
8132 KB |
Output is correct |
16 |
Correct |
44 ms |
17840 KB |
Output is correct |
17 |
Runtime error |
35 ms |
17856 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
10436 KB |
Output is correct |
2 |
Correct |
6 ms |
10436 KB |
Output is correct |
3 |
Correct |
4 ms |
8132 KB |
Output is correct |
4 |
Correct |
5 ms |
10496 KB |
Output is correct |
5 |
Correct |
5 ms |
10384 KB |
Output is correct |
6 |
Correct |
4 ms |
8132 KB |
Output is correct |
7 |
Correct |
3 ms |
8132 KB |
Output is correct |
8 |
Correct |
4 ms |
8132 KB |
Output is correct |
9 |
Correct |
48 ms |
17852 KB |
Output is correct |
10 |
Correct |
8 ms |
11204 KB |
Output is correct |
11 |
Correct |
30 ms |
14416 KB |
Output is correct |
12 |
Correct |
11 ms |
11580 KB |
Output is correct |
13 |
Correct |
10 ms |
10436 KB |
Output is correct |
14 |
Correct |
4 ms |
8132 KB |
Output is correct |
15 |
Correct |
4 ms |
8132 KB |
Output is correct |
16 |
Correct |
44 ms |
17840 KB |
Output is correct |
17 |
Correct |
5 ms |
10396 KB |
Output is correct |
18 |
Correct |
5 ms |
10436 KB |
Output is correct |
19 |
Correct |
5 ms |
10436 KB |
Output is correct |
20 |
Correct |
5 ms |
10436 KB |
Output is correct |
21 |
Correct |
5 ms |
8132 KB |
Output is correct |
22 |
Correct |
5 ms |
10436 KB |
Output is correct |
23 |
Correct |
98 ms |
27156 KB |
Output is correct |
24 |
Correct |
5 ms |
10436 KB |
Output is correct |
25 |
Correct |
5 ms |
10564 KB |
Output is correct |
26 |
Correct |
4 ms |
8260 KB |
Output is correct |
27 |
Correct |
4 ms |
8388 KB |
Output is correct |
28 |
Correct |
40 ms |
17440 KB |
Output is correct |
29 |
Correct |
74 ms |
20956 KB |
Output is correct |
30 |
Correct |
79 ms |
24060 KB |
Output is correct |
31 |
Correct |
99 ms |
27196 KB |
Output is correct |
32 |
Correct |
4 ms |
10436 KB |
Output is correct |
33 |
Correct |
6 ms |
10436 KB |
Output is correct |
34 |
Correct |
6 ms |
10436 KB |
Output is correct |
35 |
Correct |
3 ms |
8132 KB |
Output is correct |
36 |
Correct |
4 ms |
8132 KB |
Output is correct |
37 |
Correct |
5 ms |
10436 KB |
Output is correct |
38 |
Correct |
5 ms |
10436 KB |
Output is correct |
39 |
Correct |
4 ms |
10436 KB |
Output is correct |
40 |
Correct |
4 ms |
10436 KB |
Output is correct |
41 |
Correct |
4 ms |
8132 KB |
Output is correct |
42 |
Correct |
4 ms |
10492 KB |
Output is correct |
43 |
Correct |
4 ms |
8132 KB |
Output is correct |
44 |
Correct |
4 ms |
8260 KB |
Output is correct |
45 |
Correct |
44 ms |
17844 KB |
Output is correct |
46 |
Correct |
63 ms |
21388 KB |
Output is correct |
47 |
Correct |
69 ms |
21388 KB |
Output is correct |
48 |
Correct |
7 ms |
10436 KB |
Output is correct |
49 |
Correct |
5 ms |
10436 KB |
Output is correct |
50 |
Correct |
5 ms |
10436 KB |
Output is correct |
51 |
Correct |
5 ms |
10392 KB |
Output is correct |
52 |
Correct |
5 ms |
10436 KB |
Output is correct |
53 |
Correct |
5 ms |
10436 KB |
Output is correct |
54 |
Correct |
7 ms |
10396 KB |
Output is correct |
55 |
Correct |
104 ms |
29324 KB |
Output is correct |
56 |
Correct |
5 ms |
10436 KB |
Output is correct |
57 |
Correct |
6 ms |
10692 KB |
Output is correct |
58 |
Correct |
8 ms |
11052 KB |
Output is correct |
59 |
Correct |
6 ms |
8772 KB |
Output is correct |
60 |
Correct |
52 ms |
20540 KB |
Output is correct |
61 |
Correct |
70 ms |
23636 KB |
Output is correct |
62 |
Correct |
85 ms |
26464 KB |
Output is correct |
63 |
Correct |
106 ms |
29416 KB |
Output is correct |
64 |
Correct |
4 ms |
8132 KB |
Output is correct |
65 |
Correct |
6 ms |
10392 KB |
Output is correct |
66 |
Correct |
4 ms |
8132 KB |
Output is correct |
67 |
Correct |
84 ms |
26664 KB |
Output is correct |
68 |
Correct |
91 ms |
26664 KB |
Output is correct |
69 |
Correct |
84 ms |
26536 KB |
Output is correct |
70 |
Correct |
4 ms |
8260 KB |
Output is correct |
71 |
Correct |
5 ms |
8516 KB |
Output is correct |
72 |
Correct |
43 ms |
18592 KB |
Output is correct |
73 |
Correct |
65 ms |
22976 KB |
Output is correct |
74 |
Correct |
99 ms |
26676 KB |
Output is correct |
75 |
Correct |
95 ms |
28344 KB |
Output is correct |
76 |
Correct |
84 ms |
26640 KB |
Output is correct |
77 |
Correct |
4 ms |
8388 KB |
Output is correct |
78 |
Correct |
5 ms |
8644 KB |
Output is correct |
79 |
Correct |
48 ms |
18976 KB |
Output is correct |
80 |
Correct |
68 ms |
23728 KB |
Output is correct |
81 |
Correct |
95 ms |
27644 KB |
Output is correct |
82 |
Runtime error |
7 ms |
11460 KB |
Execution killed with signal 11 |
83 |
Halted |
0 ms |
0 KB |
- |