#include "parks.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
struct DSU {
int n, cnt;
vector<int> f, sz;
DSU(int n) : n(n), cnt(n) {
f.resize(n);
iota(f.begin(), f.end(), 0);
sz.resize(n, 1);
}
int find(int u) {
if (f[u] == u) return u;
return f[u] = find(f[u]);
}
void merge(int u, int v) {
u = find(u);
v = find(v);
if (u == v) return;
--cnt;
if (sz[v] > sz[u]) {
swap(u, v);
}
f[v] = u;
sz[u] += sz[v];
}
bool same(int u, int v) {
return find(u) == find(v);
}
};
int construct_roads(vector<int> x, vector<int> y) {
int n = x.size();
int N = 2e5;
vector<map<int, int>> id(N + 1);
for (int i = 0; i < n; ++i) {
id[x[i]][y[i]] = i;
}
vector<map<int, int>> vis(N + 10);
DSU dsu(n);
vector<int> u, v, a, b;
for (int i = 0; i < n; ++i) {
if (id[x[i]].count(y[i] + 2)) {
int j = id[x[i]][y[i] + 2];
dsu.merge(i, j);
u.push_back(i);
v.push_back(j);
if (x[i] == 6) {
a.push_back(x[i] + 1);
b.push_back(y[i] + 1);
vis[x[i] + 1][y[i] + 1] = 1;
} else if (x[i] == 2) {
a.push_back(x[i] - 1);
b.push_back(y[i] + 1);
vis[x[i] - 1][y[i] + 1] = 1;
} else {
if ((y[i] / 2) % 2) {
a.push_back(x[i] + 1);
b.push_back(y[i] + 1);
vis[x[i] + 1][y[i] + 1] = 1;
} else {
a.push_back(x[i] - 1);
b.push_back(y[i] + 1);
vis[x[i] - 1][y[i] + 1] = 1;
}
}
}
}
for (int i = 0; i < n; ++i) {
if (id[x[i] + 2].count(y[i])) {
int j = id[x[i] + 2][y[i]];
if (dsu.same(i, j) == 0) {
u.push_back(i);
v.push_back(j);
dsu.merge(i, j);
if (vis[x[i] + 1][y[i] - 1] == 0) {
a.push_back(x[i] + 1);
b.push_back(y[i] - 1);
vis[x[i] + 1][y[i] - 1] = 1;
} else if (vis[x[i] + 1][y[i] + 1] == 0) {
a.push_back(x[i] + 1);
b.push_back(y[i] + 1);
vis[x[i] + 1][y[i] + 1] = 1;
} else {
assert(0);
}
}
}
}
if (dsu.cnt == 1) {
build(u, v, a, b);
return 1;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
19036 KB |
Output is correct |
2 |
Correct |
8 ms |
19144 KB |
Output is correct |
3 |
Correct |
12 ms |
19036 KB |
Output is correct |
4 |
Correct |
11 ms |
19036 KB |
Output is correct |
5 |
Correct |
9 ms |
19036 KB |
Output is correct |
6 |
Correct |
9 ms |
19036 KB |
Output is correct |
7 |
Correct |
8 ms |
19160 KB |
Output is correct |
8 |
Correct |
8 ms |
19032 KB |
Output is correct |
9 |
Correct |
143 ms |
35512 KB |
Output is correct |
10 |
Correct |
19 ms |
20828 KB |
Output is correct |
11 |
Correct |
48 ms |
28112 KB |
Output is correct |
12 |
Correct |
17 ms |
21716 KB |
Output is correct |
13 |
Correct |
34 ms |
25012 KB |
Output is correct |
14 |
Correct |
9 ms |
19288 KB |
Output is correct |
15 |
Correct |
14 ms |
19292 KB |
Output is correct |
16 |
Correct |
169 ms |
35620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
19036 KB |
Output is correct |
2 |
Correct |
8 ms |
19144 KB |
Output is correct |
3 |
Correct |
12 ms |
19036 KB |
Output is correct |
4 |
Correct |
11 ms |
19036 KB |
Output is correct |
5 |
Correct |
9 ms |
19036 KB |
Output is correct |
6 |
Correct |
9 ms |
19036 KB |
Output is correct |
7 |
Correct |
8 ms |
19160 KB |
Output is correct |
8 |
Correct |
8 ms |
19032 KB |
Output is correct |
9 |
Correct |
143 ms |
35512 KB |
Output is correct |
10 |
Correct |
19 ms |
20828 KB |
Output is correct |
11 |
Correct |
48 ms |
28112 KB |
Output is correct |
12 |
Correct |
17 ms |
21716 KB |
Output is correct |
13 |
Correct |
34 ms |
25012 KB |
Output is correct |
14 |
Correct |
9 ms |
19288 KB |
Output is correct |
15 |
Correct |
14 ms |
19292 KB |
Output is correct |
16 |
Correct |
169 ms |
35620 KB |
Output is correct |
17 |
Correct |
8 ms |
19036 KB |
Output is correct |
18 |
Correct |
9 ms |
19036 KB |
Output is correct |
19 |
Correct |
9 ms |
19036 KB |
Output is correct |
20 |
Correct |
9 ms |
19036 KB |
Output is correct |
21 |
Correct |
9 ms |
19036 KB |
Output is correct |
22 |
Correct |
9 ms |
19036 KB |
Output is correct |
23 |
Correct |
382 ms |
53672 KB |
Output is correct |
24 |
Correct |
10 ms |
19036 KB |
Output is correct |
25 |
Correct |
9 ms |
19352 KB |
Output is correct |
26 |
Correct |
12 ms |
19588 KB |
Output is correct |
27 |
Correct |
12 ms |
19696 KB |
Output is correct |
28 |
Correct |
136 ms |
32988 KB |
Output is correct |
29 |
Correct |
208 ms |
39864 KB |
Output is correct |
30 |
Correct |
310 ms |
46716 KB |
Output is correct |
31 |
Correct |
384 ms |
53724 KB |
Output is correct |
32 |
Correct |
8 ms |
19036 KB |
Output is correct |
33 |
Correct |
8 ms |
19240 KB |
Output is correct |
34 |
Correct |
9 ms |
19036 KB |
Output is correct |
35 |
Correct |
8 ms |
19036 KB |
Output is correct |
36 |
Correct |
8 ms |
19032 KB |
Output is correct |
37 |
Correct |
9 ms |
19036 KB |
Output is correct |
38 |
Correct |
8 ms |
19024 KB |
Output is correct |
39 |
Correct |
11 ms |
19036 KB |
Output is correct |
40 |
Correct |
9 ms |
19036 KB |
Output is correct |
41 |
Correct |
9 ms |
19036 KB |
Output is correct |
42 |
Correct |
8 ms |
19204 KB |
Output is correct |
43 |
Correct |
10 ms |
19292 KB |
Output is correct |
44 |
Correct |
11 ms |
19548 KB |
Output is correct |
45 |
Correct |
156 ms |
36280 KB |
Output is correct |
46 |
Correct |
255 ms |
44260 KB |
Output is correct |
47 |
Correct |
246 ms |
44232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
19036 KB |
Output is correct |
2 |
Correct |
8 ms |
19144 KB |
Output is correct |
3 |
Correct |
12 ms |
19036 KB |
Output is correct |
4 |
Correct |
11 ms |
19036 KB |
Output is correct |
5 |
Correct |
9 ms |
19036 KB |
Output is correct |
6 |
Correct |
9 ms |
19036 KB |
Output is correct |
7 |
Correct |
8 ms |
19160 KB |
Output is correct |
8 |
Correct |
8 ms |
19032 KB |
Output is correct |
9 |
Correct |
143 ms |
35512 KB |
Output is correct |
10 |
Correct |
19 ms |
20828 KB |
Output is correct |
11 |
Correct |
48 ms |
28112 KB |
Output is correct |
12 |
Correct |
17 ms |
21716 KB |
Output is correct |
13 |
Correct |
34 ms |
25012 KB |
Output is correct |
14 |
Correct |
9 ms |
19288 KB |
Output is correct |
15 |
Correct |
14 ms |
19292 KB |
Output is correct |
16 |
Correct |
169 ms |
35620 KB |
Output is correct |
17 |
Correct |
8 ms |
19036 KB |
Output is correct |
18 |
Correct |
9 ms |
19036 KB |
Output is correct |
19 |
Correct |
9 ms |
19036 KB |
Output is correct |
20 |
Correct |
9 ms |
19036 KB |
Output is correct |
21 |
Correct |
9 ms |
19036 KB |
Output is correct |
22 |
Correct |
9 ms |
19036 KB |
Output is correct |
23 |
Correct |
382 ms |
53672 KB |
Output is correct |
24 |
Correct |
10 ms |
19036 KB |
Output is correct |
25 |
Correct |
9 ms |
19352 KB |
Output is correct |
26 |
Correct |
12 ms |
19588 KB |
Output is correct |
27 |
Correct |
12 ms |
19696 KB |
Output is correct |
28 |
Correct |
136 ms |
32988 KB |
Output is correct |
29 |
Correct |
208 ms |
39864 KB |
Output is correct |
30 |
Correct |
310 ms |
46716 KB |
Output is correct |
31 |
Correct |
384 ms |
53724 KB |
Output is correct |
32 |
Correct |
8 ms |
19036 KB |
Output is correct |
33 |
Correct |
8 ms |
19240 KB |
Output is correct |
34 |
Correct |
9 ms |
19036 KB |
Output is correct |
35 |
Correct |
8 ms |
19036 KB |
Output is correct |
36 |
Correct |
8 ms |
19032 KB |
Output is correct |
37 |
Correct |
9 ms |
19036 KB |
Output is correct |
38 |
Correct |
8 ms |
19024 KB |
Output is correct |
39 |
Correct |
11 ms |
19036 KB |
Output is correct |
40 |
Correct |
9 ms |
19036 KB |
Output is correct |
41 |
Correct |
9 ms |
19036 KB |
Output is correct |
42 |
Correct |
8 ms |
19204 KB |
Output is correct |
43 |
Correct |
10 ms |
19292 KB |
Output is correct |
44 |
Correct |
11 ms |
19548 KB |
Output is correct |
45 |
Correct |
156 ms |
36280 KB |
Output is correct |
46 |
Correct |
255 ms |
44260 KB |
Output is correct |
47 |
Correct |
246 ms |
44232 KB |
Output is correct |
48 |
Correct |
9 ms |
19036 KB |
Output is correct |
49 |
Correct |
8 ms |
19232 KB |
Output is correct |
50 |
Correct |
9 ms |
19032 KB |
Output is correct |
51 |
Correct |
9 ms |
19036 KB |
Output is correct |
52 |
Correct |
9 ms |
19036 KB |
Output is correct |
53 |
Correct |
8 ms |
19036 KB |
Output is correct |
54 |
Correct |
9 ms |
19036 KB |
Output is correct |
55 |
Correct |
378 ms |
53492 KB |
Output is correct |
56 |
Correct |
9 ms |
19032 KB |
Output is correct |
57 |
Correct |
10 ms |
19292 KB |
Output is correct |
58 |
Correct |
15 ms |
20076 KB |
Output is correct |
59 |
Correct |
17 ms |
20572 KB |
Output is correct |
60 |
Correct |
169 ms |
36376 KB |
Output is correct |
61 |
Correct |
236 ms |
42392 KB |
Output is correct |
62 |
Correct |
308 ms |
47784 KB |
Output is correct |
63 |
Correct |
391 ms |
53668 KB |
Output is correct |
64 |
Correct |
9 ms |
19048 KB |
Output is correct |
65 |
Correct |
9 ms |
19032 KB |
Output is correct |
66 |
Correct |
9 ms |
19036 KB |
Output is correct |
67 |
Correct |
348 ms |
53676 KB |
Output is correct |
68 |
Correct |
332 ms |
53672 KB |
Output is correct |
69 |
Correct |
343 ms |
53516 KB |
Output is correct |
70 |
Correct |
13 ms |
19552 KB |
Output is correct |
71 |
Correct |
15 ms |
20120 KB |
Output is correct |
72 |
Correct |
166 ms |
36276 KB |
Output is correct |
73 |
Correct |
257 ms |
45160 KB |
Output is correct |
74 |
Correct |
395 ms |
53668 KB |
Output is correct |
75 |
Correct |
359 ms |
53532 KB |
Output is correct |
76 |
Correct |
327 ms |
53668 KB |
Output is correct |
77 |
Correct |
15 ms |
19800 KB |
Output is correct |
78 |
Correct |
16 ms |
20572 KB |
Output is correct |
79 |
Correct |
161 ms |
36384 KB |
Output is correct |
80 |
Correct |
261 ms |
44964 KB |
Output is correct |
81 |
Correct |
401 ms |
53780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
19036 KB |
Output is correct |
2 |
Correct |
8 ms |
19144 KB |
Output is correct |
3 |
Correct |
12 ms |
19036 KB |
Output is correct |
4 |
Correct |
11 ms |
19036 KB |
Output is correct |
5 |
Correct |
9 ms |
19036 KB |
Output is correct |
6 |
Correct |
9 ms |
19036 KB |
Output is correct |
7 |
Correct |
8 ms |
19160 KB |
Output is correct |
8 |
Correct |
8 ms |
19032 KB |
Output is correct |
9 |
Correct |
143 ms |
35512 KB |
Output is correct |
10 |
Correct |
19 ms |
20828 KB |
Output is correct |
11 |
Correct |
48 ms |
28112 KB |
Output is correct |
12 |
Correct |
17 ms |
21716 KB |
Output is correct |
13 |
Correct |
34 ms |
25012 KB |
Output is correct |
14 |
Correct |
9 ms |
19288 KB |
Output is correct |
15 |
Correct |
14 ms |
19292 KB |
Output is correct |
16 |
Correct |
169 ms |
35620 KB |
Output is correct |
17 |
Correct |
8 ms |
19032 KB |
Output is correct |
18 |
Correct |
9 ms |
19032 KB |
Output is correct |
19 |
Correct |
8 ms |
19036 KB |
Output is correct |
20 |
Runtime error |
132 ms |
79936 KB |
Execution killed with signal 6 |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
19036 KB |
Output is correct |
2 |
Correct |
8 ms |
19144 KB |
Output is correct |
3 |
Correct |
12 ms |
19036 KB |
Output is correct |
4 |
Correct |
11 ms |
19036 KB |
Output is correct |
5 |
Correct |
9 ms |
19036 KB |
Output is correct |
6 |
Correct |
9 ms |
19036 KB |
Output is correct |
7 |
Correct |
8 ms |
19160 KB |
Output is correct |
8 |
Correct |
8 ms |
19032 KB |
Output is correct |
9 |
Correct |
143 ms |
35512 KB |
Output is correct |
10 |
Correct |
19 ms |
20828 KB |
Output is correct |
11 |
Correct |
48 ms |
28112 KB |
Output is correct |
12 |
Correct |
17 ms |
21716 KB |
Output is correct |
13 |
Correct |
34 ms |
25012 KB |
Output is correct |
14 |
Correct |
9 ms |
19288 KB |
Output is correct |
15 |
Correct |
14 ms |
19292 KB |
Output is correct |
16 |
Correct |
169 ms |
35620 KB |
Output is correct |
17 |
Correct |
322 ms |
52132 KB |
Output is correct |
18 |
Correct |
282 ms |
54204 KB |
Output is correct |
19 |
Runtime error |
125 ms |
82360 KB |
Execution killed with signal 6 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
19036 KB |
Output is correct |
2 |
Correct |
8 ms |
19144 KB |
Output is correct |
3 |
Correct |
12 ms |
19036 KB |
Output is correct |
4 |
Correct |
11 ms |
19036 KB |
Output is correct |
5 |
Correct |
9 ms |
19036 KB |
Output is correct |
6 |
Correct |
9 ms |
19036 KB |
Output is correct |
7 |
Correct |
8 ms |
19160 KB |
Output is correct |
8 |
Correct |
8 ms |
19032 KB |
Output is correct |
9 |
Correct |
143 ms |
35512 KB |
Output is correct |
10 |
Correct |
19 ms |
20828 KB |
Output is correct |
11 |
Correct |
48 ms |
28112 KB |
Output is correct |
12 |
Correct |
17 ms |
21716 KB |
Output is correct |
13 |
Correct |
34 ms |
25012 KB |
Output is correct |
14 |
Correct |
9 ms |
19288 KB |
Output is correct |
15 |
Correct |
14 ms |
19292 KB |
Output is correct |
16 |
Correct |
169 ms |
35620 KB |
Output is correct |
17 |
Correct |
8 ms |
19036 KB |
Output is correct |
18 |
Correct |
9 ms |
19036 KB |
Output is correct |
19 |
Correct |
9 ms |
19036 KB |
Output is correct |
20 |
Correct |
9 ms |
19036 KB |
Output is correct |
21 |
Correct |
9 ms |
19036 KB |
Output is correct |
22 |
Correct |
9 ms |
19036 KB |
Output is correct |
23 |
Correct |
382 ms |
53672 KB |
Output is correct |
24 |
Correct |
10 ms |
19036 KB |
Output is correct |
25 |
Correct |
9 ms |
19352 KB |
Output is correct |
26 |
Correct |
12 ms |
19588 KB |
Output is correct |
27 |
Correct |
12 ms |
19696 KB |
Output is correct |
28 |
Correct |
136 ms |
32988 KB |
Output is correct |
29 |
Correct |
208 ms |
39864 KB |
Output is correct |
30 |
Correct |
310 ms |
46716 KB |
Output is correct |
31 |
Correct |
384 ms |
53724 KB |
Output is correct |
32 |
Correct |
8 ms |
19036 KB |
Output is correct |
33 |
Correct |
8 ms |
19240 KB |
Output is correct |
34 |
Correct |
9 ms |
19036 KB |
Output is correct |
35 |
Correct |
8 ms |
19036 KB |
Output is correct |
36 |
Correct |
8 ms |
19032 KB |
Output is correct |
37 |
Correct |
9 ms |
19036 KB |
Output is correct |
38 |
Correct |
8 ms |
19024 KB |
Output is correct |
39 |
Correct |
11 ms |
19036 KB |
Output is correct |
40 |
Correct |
9 ms |
19036 KB |
Output is correct |
41 |
Correct |
9 ms |
19036 KB |
Output is correct |
42 |
Correct |
8 ms |
19204 KB |
Output is correct |
43 |
Correct |
10 ms |
19292 KB |
Output is correct |
44 |
Correct |
11 ms |
19548 KB |
Output is correct |
45 |
Correct |
156 ms |
36280 KB |
Output is correct |
46 |
Correct |
255 ms |
44260 KB |
Output is correct |
47 |
Correct |
246 ms |
44232 KB |
Output is correct |
48 |
Correct |
9 ms |
19036 KB |
Output is correct |
49 |
Correct |
8 ms |
19232 KB |
Output is correct |
50 |
Correct |
9 ms |
19032 KB |
Output is correct |
51 |
Correct |
9 ms |
19036 KB |
Output is correct |
52 |
Correct |
9 ms |
19036 KB |
Output is correct |
53 |
Correct |
8 ms |
19036 KB |
Output is correct |
54 |
Correct |
9 ms |
19036 KB |
Output is correct |
55 |
Correct |
378 ms |
53492 KB |
Output is correct |
56 |
Correct |
9 ms |
19032 KB |
Output is correct |
57 |
Correct |
10 ms |
19292 KB |
Output is correct |
58 |
Correct |
15 ms |
20076 KB |
Output is correct |
59 |
Correct |
17 ms |
20572 KB |
Output is correct |
60 |
Correct |
169 ms |
36376 KB |
Output is correct |
61 |
Correct |
236 ms |
42392 KB |
Output is correct |
62 |
Correct |
308 ms |
47784 KB |
Output is correct |
63 |
Correct |
391 ms |
53668 KB |
Output is correct |
64 |
Correct |
9 ms |
19048 KB |
Output is correct |
65 |
Correct |
9 ms |
19032 KB |
Output is correct |
66 |
Correct |
9 ms |
19036 KB |
Output is correct |
67 |
Correct |
348 ms |
53676 KB |
Output is correct |
68 |
Correct |
332 ms |
53672 KB |
Output is correct |
69 |
Correct |
343 ms |
53516 KB |
Output is correct |
70 |
Correct |
13 ms |
19552 KB |
Output is correct |
71 |
Correct |
15 ms |
20120 KB |
Output is correct |
72 |
Correct |
166 ms |
36276 KB |
Output is correct |
73 |
Correct |
257 ms |
45160 KB |
Output is correct |
74 |
Correct |
395 ms |
53668 KB |
Output is correct |
75 |
Correct |
359 ms |
53532 KB |
Output is correct |
76 |
Correct |
327 ms |
53668 KB |
Output is correct |
77 |
Correct |
15 ms |
19800 KB |
Output is correct |
78 |
Correct |
16 ms |
20572 KB |
Output is correct |
79 |
Correct |
161 ms |
36384 KB |
Output is correct |
80 |
Correct |
261 ms |
44964 KB |
Output is correct |
81 |
Correct |
401 ms |
53780 KB |
Output is correct |
82 |
Correct |
8 ms |
19032 KB |
Output is correct |
83 |
Correct |
9 ms |
19032 KB |
Output is correct |
84 |
Correct |
8 ms |
19036 KB |
Output is correct |
85 |
Runtime error |
132 ms |
79936 KB |
Execution killed with signal 6 |
86 |
Halted |
0 ms |
0 KB |
- |