#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;
}
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] == 4) {
a.push_back(x[i] + 1);
b.push_back(y[i] + 1);
} else {
a.push_back(x[i] - 1);
b.push_back(y[i] + 1);
}
}
if (x[i] == 2 && id[x[i] + 2].count(y[i])) {
int j = id[x[i] + 2][y[i]];
if (dsu.same(i, j) == 0) {
dsu.merge(i, j);
u.push_back(i);
v.push_back(j);
a.push_back(x[i] + 1);
b.push_back(y[i] + 1);
}
}
}
if (dsu.cnt == 1) {
build(u, v, a, b);
return 1;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9816 KB |
Output is correct |
2 |
Correct |
4 ms |
9820 KB |
Output is correct |
3 |
Correct |
4 ms |
9820 KB |
Output is correct |
4 |
Correct |
6 ms |
9816 KB |
Output is correct |
5 |
Correct |
5 ms |
9820 KB |
Output is correct |
6 |
Correct |
4 ms |
9824 KB |
Output is correct |
7 |
Correct |
4 ms |
9820 KB |
Output is correct |
8 |
Correct |
4 ms |
9820 KB |
Output is correct |
9 |
Correct |
100 ms |
21568 KB |
Output is correct |
10 |
Correct |
10 ms |
11096 KB |
Output is correct |
11 |
Correct |
37 ms |
16336 KB |
Output is correct |
12 |
Correct |
12 ms |
11608 KB |
Output is correct |
13 |
Correct |
22 ms |
13792 KB |
Output is correct |
14 |
Correct |
6 ms |
9820 KB |
Output is correct |
15 |
Correct |
6 ms |
9820 KB |
Output is correct |
16 |
Correct |
95 ms |
21676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9816 KB |
Output is correct |
2 |
Correct |
4 ms |
9820 KB |
Output is correct |
3 |
Correct |
4 ms |
9820 KB |
Output is correct |
4 |
Correct |
6 ms |
9816 KB |
Output is correct |
5 |
Correct |
5 ms |
9820 KB |
Output is correct |
6 |
Correct |
4 ms |
9824 KB |
Output is correct |
7 |
Correct |
4 ms |
9820 KB |
Output is correct |
8 |
Correct |
4 ms |
9820 KB |
Output is correct |
9 |
Correct |
100 ms |
21568 KB |
Output is correct |
10 |
Correct |
10 ms |
11096 KB |
Output is correct |
11 |
Correct |
37 ms |
16336 KB |
Output is correct |
12 |
Correct |
12 ms |
11608 KB |
Output is correct |
13 |
Correct |
22 ms |
13792 KB |
Output is correct |
14 |
Correct |
6 ms |
9820 KB |
Output is correct |
15 |
Correct |
6 ms |
9820 KB |
Output is correct |
16 |
Correct |
95 ms |
21676 KB |
Output is correct |
17 |
Correct |
6 ms |
9816 KB |
Output is correct |
18 |
Correct |
5 ms |
9820 KB |
Output is correct |
19 |
Correct |
4 ms |
9820 KB |
Output is correct |
20 |
Correct |
5 ms |
9820 KB |
Output is correct |
21 |
Correct |
4 ms |
9820 KB |
Output is correct |
22 |
Correct |
5 ms |
9820 KB |
Output is correct |
23 |
Correct |
270 ms |
37460 KB |
Output is correct |
24 |
Correct |
4 ms |
9820 KB |
Output is correct |
25 |
Correct |
5 ms |
9820 KB |
Output is correct |
26 |
Correct |
8 ms |
9960 KB |
Output is correct |
27 |
Correct |
6 ms |
10228 KB |
Output is correct |
28 |
Correct |
93 ms |
20916 KB |
Output is correct |
29 |
Correct |
158 ms |
26532 KB |
Output is correct |
30 |
Correct |
202 ms |
31928 KB |
Output is correct |
31 |
Correct |
285 ms |
37696 KB |
Output is correct |
32 |
Correct |
5 ms |
9820 KB |
Output is correct |
33 |
Correct |
4 ms |
9728 KB |
Output is correct |
34 |
Correct |
4 ms |
9820 KB |
Output is correct |
35 |
Correct |
4 ms |
9820 KB |
Output is correct |
36 |
Correct |
4 ms |
9792 KB |
Output is correct |
37 |
Correct |
4 ms |
9820 KB |
Output is correct |
38 |
Correct |
4 ms |
9652 KB |
Output is correct |
39 |
Correct |
4 ms |
9820 KB |
Output is correct |
40 |
Correct |
5 ms |
9820 KB |
Output is correct |
41 |
Correct |
5 ms |
9816 KB |
Output is correct |
42 |
Correct |
4 ms |
9820 KB |
Output is correct |
43 |
Correct |
5 ms |
9820 KB |
Output is correct |
44 |
Correct |
6 ms |
10076 KB |
Output is correct |
45 |
Correct |
105 ms |
22324 KB |
Output is correct |
46 |
Correct |
170 ms |
28072 KB |
Output is correct |
47 |
Correct |
166 ms |
27984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9816 KB |
Output is correct |
2 |
Correct |
4 ms |
9820 KB |
Output is correct |
3 |
Correct |
4 ms |
9820 KB |
Output is correct |
4 |
Correct |
6 ms |
9816 KB |
Output is correct |
5 |
Correct |
5 ms |
9820 KB |
Output is correct |
6 |
Correct |
4 ms |
9824 KB |
Output is correct |
7 |
Correct |
4 ms |
9820 KB |
Output is correct |
8 |
Correct |
4 ms |
9820 KB |
Output is correct |
9 |
Correct |
100 ms |
21568 KB |
Output is correct |
10 |
Correct |
10 ms |
11096 KB |
Output is correct |
11 |
Correct |
37 ms |
16336 KB |
Output is correct |
12 |
Correct |
12 ms |
11608 KB |
Output is correct |
13 |
Correct |
22 ms |
13792 KB |
Output is correct |
14 |
Correct |
6 ms |
9820 KB |
Output is correct |
15 |
Correct |
6 ms |
9820 KB |
Output is correct |
16 |
Correct |
95 ms |
21676 KB |
Output is correct |
17 |
Correct |
6 ms |
9816 KB |
Output is correct |
18 |
Correct |
5 ms |
9820 KB |
Output is correct |
19 |
Correct |
4 ms |
9820 KB |
Output is correct |
20 |
Correct |
5 ms |
9820 KB |
Output is correct |
21 |
Correct |
4 ms |
9820 KB |
Output is correct |
22 |
Correct |
5 ms |
9820 KB |
Output is correct |
23 |
Correct |
270 ms |
37460 KB |
Output is correct |
24 |
Correct |
4 ms |
9820 KB |
Output is correct |
25 |
Correct |
5 ms |
9820 KB |
Output is correct |
26 |
Correct |
8 ms |
9960 KB |
Output is correct |
27 |
Correct |
6 ms |
10228 KB |
Output is correct |
28 |
Correct |
93 ms |
20916 KB |
Output is correct |
29 |
Correct |
158 ms |
26532 KB |
Output is correct |
30 |
Correct |
202 ms |
31928 KB |
Output is correct |
31 |
Correct |
285 ms |
37696 KB |
Output is correct |
32 |
Correct |
5 ms |
9820 KB |
Output is correct |
33 |
Correct |
4 ms |
9728 KB |
Output is correct |
34 |
Correct |
4 ms |
9820 KB |
Output is correct |
35 |
Correct |
4 ms |
9820 KB |
Output is correct |
36 |
Correct |
4 ms |
9792 KB |
Output is correct |
37 |
Correct |
4 ms |
9820 KB |
Output is correct |
38 |
Correct |
4 ms |
9652 KB |
Output is correct |
39 |
Correct |
4 ms |
9820 KB |
Output is correct |
40 |
Correct |
5 ms |
9820 KB |
Output is correct |
41 |
Correct |
5 ms |
9816 KB |
Output is correct |
42 |
Correct |
4 ms |
9820 KB |
Output is correct |
43 |
Correct |
5 ms |
9820 KB |
Output is correct |
44 |
Correct |
6 ms |
10076 KB |
Output is correct |
45 |
Correct |
105 ms |
22324 KB |
Output is correct |
46 |
Correct |
170 ms |
28072 KB |
Output is correct |
47 |
Correct |
166 ms |
27984 KB |
Output is correct |
48 |
Incorrect |
5 ms |
9816 KB |
Solution announced impossible, but it is possible. |
49 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9816 KB |
Output is correct |
2 |
Correct |
4 ms |
9820 KB |
Output is correct |
3 |
Correct |
4 ms |
9820 KB |
Output is correct |
4 |
Correct |
6 ms |
9816 KB |
Output is correct |
5 |
Correct |
5 ms |
9820 KB |
Output is correct |
6 |
Correct |
4 ms |
9824 KB |
Output is correct |
7 |
Correct |
4 ms |
9820 KB |
Output is correct |
8 |
Correct |
4 ms |
9820 KB |
Output is correct |
9 |
Correct |
100 ms |
21568 KB |
Output is correct |
10 |
Correct |
10 ms |
11096 KB |
Output is correct |
11 |
Correct |
37 ms |
16336 KB |
Output is correct |
12 |
Correct |
12 ms |
11608 KB |
Output is correct |
13 |
Correct |
22 ms |
13792 KB |
Output is correct |
14 |
Correct |
6 ms |
9820 KB |
Output is correct |
15 |
Correct |
6 ms |
9820 KB |
Output is correct |
16 |
Correct |
95 ms |
21676 KB |
Output is correct |
17 |
Incorrect |
4 ms |
9820 KB |
Solution announced impossible, but it is possible. |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9816 KB |
Output is correct |
2 |
Correct |
4 ms |
9820 KB |
Output is correct |
3 |
Correct |
4 ms |
9820 KB |
Output is correct |
4 |
Correct |
6 ms |
9816 KB |
Output is correct |
5 |
Correct |
5 ms |
9820 KB |
Output is correct |
6 |
Correct |
4 ms |
9824 KB |
Output is correct |
7 |
Correct |
4 ms |
9820 KB |
Output is correct |
8 |
Correct |
4 ms |
9820 KB |
Output is correct |
9 |
Correct |
100 ms |
21568 KB |
Output is correct |
10 |
Correct |
10 ms |
11096 KB |
Output is correct |
11 |
Correct |
37 ms |
16336 KB |
Output is correct |
12 |
Correct |
12 ms |
11608 KB |
Output is correct |
13 |
Correct |
22 ms |
13792 KB |
Output is correct |
14 |
Correct |
6 ms |
9820 KB |
Output is correct |
15 |
Correct |
6 ms |
9820 KB |
Output is correct |
16 |
Correct |
95 ms |
21676 KB |
Output is correct |
17 |
Incorrect |
148 ms |
25400 KB |
Solution announced impossible, but it is possible. |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9816 KB |
Output is correct |
2 |
Correct |
4 ms |
9820 KB |
Output is correct |
3 |
Correct |
4 ms |
9820 KB |
Output is correct |
4 |
Correct |
6 ms |
9816 KB |
Output is correct |
5 |
Correct |
5 ms |
9820 KB |
Output is correct |
6 |
Correct |
4 ms |
9824 KB |
Output is correct |
7 |
Correct |
4 ms |
9820 KB |
Output is correct |
8 |
Correct |
4 ms |
9820 KB |
Output is correct |
9 |
Correct |
100 ms |
21568 KB |
Output is correct |
10 |
Correct |
10 ms |
11096 KB |
Output is correct |
11 |
Correct |
37 ms |
16336 KB |
Output is correct |
12 |
Correct |
12 ms |
11608 KB |
Output is correct |
13 |
Correct |
22 ms |
13792 KB |
Output is correct |
14 |
Correct |
6 ms |
9820 KB |
Output is correct |
15 |
Correct |
6 ms |
9820 KB |
Output is correct |
16 |
Correct |
95 ms |
21676 KB |
Output is correct |
17 |
Correct |
6 ms |
9816 KB |
Output is correct |
18 |
Correct |
5 ms |
9820 KB |
Output is correct |
19 |
Correct |
4 ms |
9820 KB |
Output is correct |
20 |
Correct |
5 ms |
9820 KB |
Output is correct |
21 |
Correct |
4 ms |
9820 KB |
Output is correct |
22 |
Correct |
5 ms |
9820 KB |
Output is correct |
23 |
Correct |
270 ms |
37460 KB |
Output is correct |
24 |
Correct |
4 ms |
9820 KB |
Output is correct |
25 |
Correct |
5 ms |
9820 KB |
Output is correct |
26 |
Correct |
8 ms |
9960 KB |
Output is correct |
27 |
Correct |
6 ms |
10228 KB |
Output is correct |
28 |
Correct |
93 ms |
20916 KB |
Output is correct |
29 |
Correct |
158 ms |
26532 KB |
Output is correct |
30 |
Correct |
202 ms |
31928 KB |
Output is correct |
31 |
Correct |
285 ms |
37696 KB |
Output is correct |
32 |
Correct |
5 ms |
9820 KB |
Output is correct |
33 |
Correct |
4 ms |
9728 KB |
Output is correct |
34 |
Correct |
4 ms |
9820 KB |
Output is correct |
35 |
Correct |
4 ms |
9820 KB |
Output is correct |
36 |
Correct |
4 ms |
9792 KB |
Output is correct |
37 |
Correct |
4 ms |
9820 KB |
Output is correct |
38 |
Correct |
4 ms |
9652 KB |
Output is correct |
39 |
Correct |
4 ms |
9820 KB |
Output is correct |
40 |
Correct |
5 ms |
9820 KB |
Output is correct |
41 |
Correct |
5 ms |
9816 KB |
Output is correct |
42 |
Correct |
4 ms |
9820 KB |
Output is correct |
43 |
Correct |
5 ms |
9820 KB |
Output is correct |
44 |
Correct |
6 ms |
10076 KB |
Output is correct |
45 |
Correct |
105 ms |
22324 KB |
Output is correct |
46 |
Correct |
170 ms |
28072 KB |
Output is correct |
47 |
Correct |
166 ms |
27984 KB |
Output is correct |
48 |
Incorrect |
5 ms |
9816 KB |
Solution announced impossible, but it is possible. |
49 |
Halted |
0 ms |
0 KB |
- |