#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
constexpr int kMinX = 2;
constexpr int kMidX = 4;
constexpr int kMaxX = 6;
int construct_roads(std::vector<int> X, std::vector<int> Y) {
int N = X.size();
vector<map<int, int>> pos(kMaxX + 1);
for (int i = 0; i < N; ++i) {
pos[X[i]][Y[i]] = i;
}
vector<int> parent(N);
iota(parent.begin(), parent.end(), 0);
function<int(int)> find_root = [&] (int u) {
return parent[u] = u == parent[u] ? u : find_root(parent[u]);
};
for (int i = 0; i < N; ++i) {
if (pos[X[i]].count(Y[i] + 2)) {
parent[find_root(i)] = find_root(pos[X[i]][Y[i] + 2]);
}
if (X[i] < kMaxX && pos[X[i] + 2].count(Y[i])) {
parent[find_root(i)] = find_root(pos[X[i] + 2][Y[i]]);
}
}
for (int i = 0; i < N; ++i) {
if (find_root(i) != find_root(0)) {
return 0;
}
}
vector<int> U, V, A, B;
for (int x : {kMinX, kMaxX}) {
for (map<int, int>::iterator it = pos[x].begin();
it != pos[x].end();
++it) {
int y = it->first;
if (pos[x].count(y + 2)) {
U.push_back(pos[x][y]);
V.push_back(pos[x][y + 2]);
A.push_back(x == kMinX ? x - 1 : x + 1);
B.push_back(y + 1);
}
}
}
for (map<int, int>::iterator it = pos[kMidX].begin();
it != pos[kMidX].end();
++it) {
int x = kMidX;
int y = it->first;
if (pos[x].count(y + 2)) {
U.push_back(pos[x][y]);
V.push_back(pos[x][y + 2]);
B.push_back(y + 1);
if (y & 2) {
A.push_back(x + 1);
if (pos[x - 2].count(y)) {
U.push_back(pos[x][y]);
V.push_back(pos[x - 2][y]);
A.push_back(x - 1);
B.push_back(y + 1);
}
if (pos[x + 2].count(y)) {
if (pos[x + 2].count(y - 2) == 0 || pos[x].count(y - 2) == 0) {
U.push_back(pos[x][y]);
V.push_back(pos[x + 2][y]);
A.push_back(x + 1);
B.push_back(y - 1);
}
}
} else {
A.push_back(x - 1);
if (pos[x - 2].count(y)) {
if (pos[x - 2].count(y - 2) == 0 || pos[x].count(y - 2) == 0) {
U.push_back(pos[x][y]);
V.push_back(pos[x - 2][y]);
A.push_back(x - 1);
B.push_back(y - 1);
}
}
if (pos[x + 2].count(y)) {
U.push_back(pos[x][y]);
V.push_back(pos[x + 2][y]);
A.push_back(x + 1);
B.push_back(y + 1);
}
}
} else {
for (int d : {-1, 1}) {
if (pos[x + d * 2].count(y)) {
U.push_back(pos[x][y]);
V.push_back(pos[x + d * 2][y]);
A.push_back(x + d);
B.push_back(y + 1);
}
}
}
}
build(U, V, A, B);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
192 ms |
11732 KB |
Output is correct |
10 |
Correct |
29 ms |
2056 KB |
Output is correct |
11 |
Correct |
91 ms |
9020 KB |
Output is correct |
12 |
Correct |
27 ms |
2888 KB |
Output is correct |
13 |
Correct |
36 ms |
4548 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
3 ms |
332 KB |
Output is correct |
16 |
Correct |
202 ms |
11776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
192 ms |
11732 KB |
Output is correct |
10 |
Correct |
29 ms |
2056 KB |
Output is correct |
11 |
Correct |
91 ms |
9020 KB |
Output is correct |
12 |
Correct |
27 ms |
2888 KB |
Output is correct |
13 |
Correct |
36 ms |
4548 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
3 ms |
332 KB |
Output is correct |
16 |
Correct |
202 ms |
11776 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
900 ms |
25416 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
3 ms |
460 KB |
Output is correct |
26 |
Correct |
5 ms |
460 KB |
Output is correct |
27 |
Correct |
5 ms |
460 KB |
Output is correct |
28 |
Correct |
208 ms |
10368 KB |
Output is correct |
29 |
Correct |
307 ms |
15376 KB |
Output is correct |
30 |
Correct |
606 ms |
20456 KB |
Output is correct |
31 |
Correct |
755 ms |
25500 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
1 ms |
204 KB |
Output is correct |
37 |
Correct |
1 ms |
204 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
1 ms |
204 KB |
Output is correct |
41 |
Correct |
1 ms |
204 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
2 ms |
332 KB |
Output is correct |
44 |
Correct |
3 ms |
460 KB |
Output is correct |
45 |
Correct |
217 ms |
11684 KB |
Output is correct |
46 |
Correct |
459 ms |
16836 KB |
Output is correct |
47 |
Correct |
493 ms |
16808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
192 ms |
11732 KB |
Output is correct |
10 |
Correct |
29 ms |
2056 KB |
Output is correct |
11 |
Correct |
91 ms |
9020 KB |
Output is correct |
12 |
Correct |
27 ms |
2888 KB |
Output is correct |
13 |
Correct |
36 ms |
4548 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
3 ms |
332 KB |
Output is correct |
16 |
Correct |
202 ms |
11776 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
900 ms |
25416 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
3 ms |
460 KB |
Output is correct |
26 |
Correct |
5 ms |
460 KB |
Output is correct |
27 |
Correct |
5 ms |
460 KB |
Output is correct |
28 |
Correct |
208 ms |
10368 KB |
Output is correct |
29 |
Correct |
307 ms |
15376 KB |
Output is correct |
30 |
Correct |
606 ms |
20456 KB |
Output is correct |
31 |
Correct |
755 ms |
25500 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
1 ms |
204 KB |
Output is correct |
37 |
Correct |
1 ms |
204 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
1 ms |
204 KB |
Output is correct |
41 |
Correct |
1 ms |
204 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
2 ms |
332 KB |
Output is correct |
44 |
Correct |
3 ms |
460 KB |
Output is correct |
45 |
Correct |
217 ms |
11684 KB |
Output is correct |
46 |
Correct |
459 ms |
16836 KB |
Output is correct |
47 |
Correct |
493 ms |
16808 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
1 ms |
204 KB |
Output is correct |
50 |
Correct |
1 ms |
204 KB |
Output is correct |
51 |
Correct |
1 ms |
204 KB |
Output is correct |
52 |
Correct |
1 ms |
204 KB |
Output is correct |
53 |
Correct |
1 ms |
204 KB |
Output is correct |
54 |
Correct |
1 ms |
204 KB |
Output is correct |
55 |
Correct |
761 ms |
26212 KB |
Output is correct |
56 |
Correct |
1 ms |
204 KB |
Output is correct |
57 |
Correct |
4 ms |
588 KB |
Output is correct |
58 |
Correct |
11 ms |
1228 KB |
Output is correct |
59 |
Correct |
10 ms |
952 KB |
Output is correct |
60 |
Correct |
378 ms |
13300 KB |
Output is correct |
61 |
Correct |
395 ms |
17768 KB |
Output is correct |
62 |
Correct |
582 ms |
21692 KB |
Output is correct |
63 |
Correct |
810 ms |
26220 KB |
Output is correct |
64 |
Correct |
1 ms |
204 KB |
Output is correct |
65 |
Correct |
1 ms |
204 KB |
Output is correct |
66 |
Correct |
1 ms |
204 KB |
Output is correct |
67 |
Correct |
580 ms |
23112 KB |
Output is correct |
68 |
Correct |
583 ms |
23184 KB |
Output is correct |
69 |
Correct |
544 ms |
22992 KB |
Output is correct |
70 |
Correct |
4 ms |
460 KB |
Output is correct |
71 |
Correct |
8 ms |
732 KB |
Output is correct |
72 |
Correct |
266 ms |
11780 KB |
Output is correct |
73 |
Correct |
482 ms |
17384 KB |
Output is correct |
74 |
Correct |
761 ms |
23160 KB |
Output is correct |
75 |
Correct |
684 ms |
25032 KB |
Output is correct |
76 |
Correct |
603 ms |
23136 KB |
Output is correct |
77 |
Correct |
5 ms |
588 KB |
Output is correct |
78 |
Correct |
15 ms |
844 KB |
Output is correct |
79 |
Correct |
280 ms |
12160 KB |
Output is correct |
80 |
Correct |
479 ms |
18120 KB |
Output is correct |
81 |
Correct |
726 ms |
24052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
192 ms |
11732 KB |
Output is correct |
10 |
Correct |
29 ms |
2056 KB |
Output is correct |
11 |
Correct |
91 ms |
9020 KB |
Output is correct |
12 |
Correct |
27 ms |
2888 KB |
Output is correct |
13 |
Correct |
36 ms |
4548 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
3 ms |
332 KB |
Output is correct |
16 |
Correct |
202 ms |
11776 KB |
Output is correct |
17 |
Runtime error |
1 ms |
296 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
192 ms |
11732 KB |
Output is correct |
10 |
Correct |
29 ms |
2056 KB |
Output is correct |
11 |
Correct |
91 ms |
9020 KB |
Output is correct |
12 |
Correct |
27 ms |
2888 KB |
Output is correct |
13 |
Correct |
36 ms |
4548 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
3 ms |
332 KB |
Output is correct |
16 |
Correct |
202 ms |
11776 KB |
Output is correct |
17 |
Runtime error |
50 ms |
6716 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
192 ms |
11732 KB |
Output is correct |
10 |
Correct |
29 ms |
2056 KB |
Output is correct |
11 |
Correct |
91 ms |
9020 KB |
Output is correct |
12 |
Correct |
27 ms |
2888 KB |
Output is correct |
13 |
Correct |
36 ms |
4548 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
3 ms |
332 KB |
Output is correct |
16 |
Correct |
202 ms |
11776 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
900 ms |
25416 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
3 ms |
460 KB |
Output is correct |
26 |
Correct |
5 ms |
460 KB |
Output is correct |
27 |
Correct |
5 ms |
460 KB |
Output is correct |
28 |
Correct |
208 ms |
10368 KB |
Output is correct |
29 |
Correct |
307 ms |
15376 KB |
Output is correct |
30 |
Correct |
606 ms |
20456 KB |
Output is correct |
31 |
Correct |
755 ms |
25500 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
1 ms |
204 KB |
Output is correct |
37 |
Correct |
1 ms |
204 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
1 ms |
204 KB |
Output is correct |
41 |
Correct |
1 ms |
204 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
2 ms |
332 KB |
Output is correct |
44 |
Correct |
3 ms |
460 KB |
Output is correct |
45 |
Correct |
217 ms |
11684 KB |
Output is correct |
46 |
Correct |
459 ms |
16836 KB |
Output is correct |
47 |
Correct |
493 ms |
16808 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
1 ms |
204 KB |
Output is correct |
50 |
Correct |
1 ms |
204 KB |
Output is correct |
51 |
Correct |
1 ms |
204 KB |
Output is correct |
52 |
Correct |
1 ms |
204 KB |
Output is correct |
53 |
Correct |
1 ms |
204 KB |
Output is correct |
54 |
Correct |
1 ms |
204 KB |
Output is correct |
55 |
Correct |
761 ms |
26212 KB |
Output is correct |
56 |
Correct |
1 ms |
204 KB |
Output is correct |
57 |
Correct |
4 ms |
588 KB |
Output is correct |
58 |
Correct |
11 ms |
1228 KB |
Output is correct |
59 |
Correct |
10 ms |
952 KB |
Output is correct |
60 |
Correct |
378 ms |
13300 KB |
Output is correct |
61 |
Correct |
395 ms |
17768 KB |
Output is correct |
62 |
Correct |
582 ms |
21692 KB |
Output is correct |
63 |
Correct |
810 ms |
26220 KB |
Output is correct |
64 |
Correct |
1 ms |
204 KB |
Output is correct |
65 |
Correct |
1 ms |
204 KB |
Output is correct |
66 |
Correct |
1 ms |
204 KB |
Output is correct |
67 |
Correct |
580 ms |
23112 KB |
Output is correct |
68 |
Correct |
583 ms |
23184 KB |
Output is correct |
69 |
Correct |
544 ms |
22992 KB |
Output is correct |
70 |
Correct |
4 ms |
460 KB |
Output is correct |
71 |
Correct |
8 ms |
732 KB |
Output is correct |
72 |
Correct |
266 ms |
11780 KB |
Output is correct |
73 |
Correct |
482 ms |
17384 KB |
Output is correct |
74 |
Correct |
761 ms |
23160 KB |
Output is correct |
75 |
Correct |
684 ms |
25032 KB |
Output is correct |
76 |
Correct |
603 ms |
23136 KB |
Output is correct |
77 |
Correct |
5 ms |
588 KB |
Output is correct |
78 |
Correct |
15 ms |
844 KB |
Output is correct |
79 |
Correct |
280 ms |
12160 KB |
Output is correct |
80 |
Correct |
479 ms |
18120 KB |
Output is correct |
81 |
Correct |
726 ms |
24052 KB |
Output is correct |
82 |
Runtime error |
1 ms |
296 KB |
Execution killed with signal 11 |
83 |
Halted |
0 ms |
0 KB |
- |