#include "parks.h"
#include "bits/stdc++.h"
using namespace std;
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define forn(i, n) for(int i = 0; i < n; ++i)
const int N = 2e5 + 10;
int p[N];
int get(int a) {
return p[a] = (a == p[a] ? a : get(p[a]));
}
bool uni(int a, int b) {
a = get(a), b = get(b);
if(a == b) return false;
p[a] = b;
return true;
}
int construct_roads(vector<int> x, vector<int> y) {
forn(i, N) p[i] = i;
if (x.size() == 1) {
build({}, {}, {}, {});
return 1;
}
vector<int> u, v, a, b;
vector<pair<int, int>> points;
map<pair<int, int>, int> idx;
vector<int> bruh[N];
for(int i = 0; i < sz(x); ++i) {
bruh[y[i]].push_back(i);
idx[{x[i], y[i]}] = i;
points.push_back({x[i], y[i]});
}
sort(all(points));
for(int i = 0; i + 1 < sz(points); ++i) {
if(points[i].first == points[i + 1].first) {
if(points[i].second + 2 != points[i + 1].second) continue;
if(points[i].first == 2 && uni(idx[points[i]], idx[points[i + 1]])) {
u.push_back(idx[points[i]]), v.push_back(idx[points[i + 1]]);
a.push_back(points[i].first - 1);
b.push_back(points[i].second + 1);
} else if(points[i].first == 4 && uni(idx[points[i]], idx[points[i + 1]])) {
u.push_back(idx[points[i]]), v.push_back(idx[points[i + 1]]);
a.push_back(points[i].first + 1);
b.push_back(points[i].second + 1);
}
}
}
for(auto c: bruh) {
if(sz(c) >= 2) {
assert(sz(c) == 2);
if(uni(c[0], c[1])) {
u.push_back(c[0]);
v.push_back(c[1]);
a.push_back(3);
b.push_back(y[c[0]] - 1);
}
}
}
for(int i = 1; i < sz(x); ++i) {
if(get(i) != get(0)) return 0;
}
build(u, v, a, b);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5716 KB |
Output is correct |
2 |
Correct |
4 ms |
5768 KB |
Output is correct |
3 |
Correct |
4 ms |
5716 KB |
Output is correct |
4 |
Correct |
3 ms |
5688 KB |
Output is correct |
5 |
Correct |
3 ms |
5716 KB |
Output is correct |
6 |
Correct |
4 ms |
5716 KB |
Output is correct |
7 |
Correct |
4 ms |
5716 KB |
Output is correct |
8 |
Correct |
3 ms |
5716 KB |
Output is correct |
9 |
Correct |
179 ms |
24464 KB |
Output is correct |
10 |
Correct |
13 ms |
7792 KB |
Output is correct |
11 |
Correct |
64 ms |
15824 KB |
Output is correct |
12 |
Correct |
18 ms |
8660 KB |
Output is correct |
13 |
Correct |
40 ms |
12804 KB |
Output is correct |
14 |
Correct |
5 ms |
5844 KB |
Output is correct |
15 |
Correct |
5 ms |
5972 KB |
Output is correct |
16 |
Correct |
173 ms |
24024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5716 KB |
Output is correct |
2 |
Correct |
4 ms |
5768 KB |
Output is correct |
3 |
Correct |
4 ms |
5716 KB |
Output is correct |
4 |
Correct |
3 ms |
5688 KB |
Output is correct |
5 |
Correct |
3 ms |
5716 KB |
Output is correct |
6 |
Correct |
4 ms |
5716 KB |
Output is correct |
7 |
Correct |
4 ms |
5716 KB |
Output is correct |
8 |
Correct |
3 ms |
5716 KB |
Output is correct |
9 |
Correct |
179 ms |
24464 KB |
Output is correct |
10 |
Correct |
13 ms |
7792 KB |
Output is correct |
11 |
Correct |
64 ms |
15824 KB |
Output is correct |
12 |
Correct |
18 ms |
8660 KB |
Output is correct |
13 |
Correct |
40 ms |
12804 KB |
Output is correct |
14 |
Correct |
5 ms |
5844 KB |
Output is correct |
15 |
Correct |
5 ms |
5972 KB |
Output is correct |
16 |
Correct |
173 ms |
24024 KB |
Output is correct |
17 |
Correct |
3 ms |
5692 KB |
Output is correct |
18 |
Correct |
3 ms |
5716 KB |
Output is correct |
19 |
Correct |
4 ms |
5716 KB |
Output is correct |
20 |
Correct |
3 ms |
5716 KB |
Output is correct |
21 |
Correct |
4 ms |
5716 KB |
Output is correct |
22 |
Correct |
3 ms |
5716 KB |
Output is correct |
23 |
Correct |
396 ms |
40288 KB |
Output is correct |
24 |
Correct |
3 ms |
5716 KB |
Output is correct |
25 |
Correct |
5 ms |
5972 KB |
Output is correct |
26 |
Correct |
5 ms |
6100 KB |
Output is correct |
27 |
Correct |
6 ms |
6228 KB |
Output is correct |
28 |
Correct |
143 ms |
19764 KB |
Output is correct |
29 |
Correct |
199 ms |
26068 KB |
Output is correct |
30 |
Correct |
297 ms |
34012 KB |
Output is correct |
31 |
Correct |
381 ms |
40184 KB |
Output is correct |
32 |
Correct |
4 ms |
5716 KB |
Output is correct |
33 |
Correct |
4 ms |
5716 KB |
Output is correct |
34 |
Correct |
4 ms |
5716 KB |
Output is correct |
35 |
Correct |
3 ms |
5716 KB |
Output is correct |
36 |
Correct |
4 ms |
5716 KB |
Output is correct |
37 |
Correct |
3 ms |
5716 KB |
Output is correct |
38 |
Correct |
3 ms |
5692 KB |
Output is correct |
39 |
Correct |
4 ms |
5716 KB |
Output is correct |
40 |
Correct |
4 ms |
5716 KB |
Output is correct |
41 |
Correct |
3 ms |
5716 KB |
Output is correct |
42 |
Correct |
4 ms |
5716 KB |
Output is correct |
43 |
Correct |
5 ms |
5972 KB |
Output is correct |
44 |
Correct |
6 ms |
6232 KB |
Output is correct |
45 |
Correct |
157 ms |
22940 KB |
Output is correct |
46 |
Correct |
260 ms |
31636 KB |
Output is correct |
47 |
Correct |
254 ms |
31620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5716 KB |
Output is correct |
2 |
Correct |
4 ms |
5768 KB |
Output is correct |
3 |
Correct |
4 ms |
5716 KB |
Output is correct |
4 |
Correct |
3 ms |
5688 KB |
Output is correct |
5 |
Correct |
3 ms |
5716 KB |
Output is correct |
6 |
Correct |
4 ms |
5716 KB |
Output is correct |
7 |
Correct |
4 ms |
5716 KB |
Output is correct |
8 |
Correct |
3 ms |
5716 KB |
Output is correct |
9 |
Correct |
179 ms |
24464 KB |
Output is correct |
10 |
Correct |
13 ms |
7792 KB |
Output is correct |
11 |
Correct |
64 ms |
15824 KB |
Output is correct |
12 |
Correct |
18 ms |
8660 KB |
Output is correct |
13 |
Correct |
40 ms |
12804 KB |
Output is correct |
14 |
Correct |
5 ms |
5844 KB |
Output is correct |
15 |
Correct |
5 ms |
5972 KB |
Output is correct |
16 |
Correct |
173 ms |
24024 KB |
Output is correct |
17 |
Correct |
3 ms |
5692 KB |
Output is correct |
18 |
Correct |
3 ms |
5716 KB |
Output is correct |
19 |
Correct |
4 ms |
5716 KB |
Output is correct |
20 |
Correct |
3 ms |
5716 KB |
Output is correct |
21 |
Correct |
4 ms |
5716 KB |
Output is correct |
22 |
Correct |
3 ms |
5716 KB |
Output is correct |
23 |
Correct |
396 ms |
40288 KB |
Output is correct |
24 |
Correct |
3 ms |
5716 KB |
Output is correct |
25 |
Correct |
5 ms |
5972 KB |
Output is correct |
26 |
Correct |
5 ms |
6100 KB |
Output is correct |
27 |
Correct |
6 ms |
6228 KB |
Output is correct |
28 |
Correct |
143 ms |
19764 KB |
Output is correct |
29 |
Correct |
199 ms |
26068 KB |
Output is correct |
30 |
Correct |
297 ms |
34012 KB |
Output is correct |
31 |
Correct |
381 ms |
40184 KB |
Output is correct |
32 |
Correct |
4 ms |
5716 KB |
Output is correct |
33 |
Correct |
4 ms |
5716 KB |
Output is correct |
34 |
Correct |
4 ms |
5716 KB |
Output is correct |
35 |
Correct |
3 ms |
5716 KB |
Output is correct |
36 |
Correct |
4 ms |
5716 KB |
Output is correct |
37 |
Correct |
3 ms |
5716 KB |
Output is correct |
38 |
Correct |
3 ms |
5692 KB |
Output is correct |
39 |
Correct |
4 ms |
5716 KB |
Output is correct |
40 |
Correct |
4 ms |
5716 KB |
Output is correct |
41 |
Correct |
3 ms |
5716 KB |
Output is correct |
42 |
Correct |
4 ms |
5716 KB |
Output is correct |
43 |
Correct |
5 ms |
5972 KB |
Output is correct |
44 |
Correct |
6 ms |
6232 KB |
Output is correct |
45 |
Correct |
157 ms |
22940 KB |
Output is correct |
46 |
Correct |
260 ms |
31636 KB |
Output is correct |
47 |
Correct |
254 ms |
31620 KB |
Output is correct |
48 |
Incorrect |
4 ms |
5716 KB |
Tree (a[1], b[1]) = (3, 1) is not adjacent to edge between u[1]=0 @(6, 2) and v[1]=1 @(4, 2) |
49 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5716 KB |
Output is correct |
2 |
Correct |
4 ms |
5768 KB |
Output is correct |
3 |
Correct |
4 ms |
5716 KB |
Output is correct |
4 |
Correct |
3 ms |
5688 KB |
Output is correct |
5 |
Correct |
3 ms |
5716 KB |
Output is correct |
6 |
Correct |
4 ms |
5716 KB |
Output is correct |
7 |
Correct |
4 ms |
5716 KB |
Output is correct |
8 |
Correct |
3 ms |
5716 KB |
Output is correct |
9 |
Correct |
179 ms |
24464 KB |
Output is correct |
10 |
Correct |
13 ms |
7792 KB |
Output is correct |
11 |
Correct |
64 ms |
15824 KB |
Output is correct |
12 |
Correct |
18 ms |
8660 KB |
Output is correct |
13 |
Correct |
40 ms |
12804 KB |
Output is correct |
14 |
Correct |
5 ms |
5844 KB |
Output is correct |
15 |
Correct |
5 ms |
5972 KB |
Output is correct |
16 |
Correct |
173 ms |
24024 KB |
Output is correct |
17 |
Incorrect |
4 ms |
5680 KB |
Solution announced impossible, but it is possible. |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5716 KB |
Output is correct |
2 |
Correct |
4 ms |
5768 KB |
Output is correct |
3 |
Correct |
4 ms |
5716 KB |
Output is correct |
4 |
Correct |
3 ms |
5688 KB |
Output is correct |
5 |
Correct |
3 ms |
5716 KB |
Output is correct |
6 |
Correct |
4 ms |
5716 KB |
Output is correct |
7 |
Correct |
4 ms |
5716 KB |
Output is correct |
8 |
Correct |
3 ms |
5716 KB |
Output is correct |
9 |
Correct |
179 ms |
24464 KB |
Output is correct |
10 |
Correct |
13 ms |
7792 KB |
Output is correct |
11 |
Correct |
64 ms |
15824 KB |
Output is correct |
12 |
Correct |
18 ms |
8660 KB |
Output is correct |
13 |
Correct |
40 ms |
12804 KB |
Output is correct |
14 |
Correct |
5 ms |
5844 KB |
Output is correct |
15 |
Correct |
5 ms |
5972 KB |
Output is correct |
16 |
Correct |
173 ms |
24024 KB |
Output is correct |
17 |
Runtime error |
215 ms |
53600 KB |
Execution killed with signal 6 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5716 KB |
Output is correct |
2 |
Correct |
4 ms |
5768 KB |
Output is correct |
3 |
Correct |
4 ms |
5716 KB |
Output is correct |
4 |
Correct |
3 ms |
5688 KB |
Output is correct |
5 |
Correct |
3 ms |
5716 KB |
Output is correct |
6 |
Correct |
4 ms |
5716 KB |
Output is correct |
7 |
Correct |
4 ms |
5716 KB |
Output is correct |
8 |
Correct |
3 ms |
5716 KB |
Output is correct |
9 |
Correct |
179 ms |
24464 KB |
Output is correct |
10 |
Correct |
13 ms |
7792 KB |
Output is correct |
11 |
Correct |
64 ms |
15824 KB |
Output is correct |
12 |
Correct |
18 ms |
8660 KB |
Output is correct |
13 |
Correct |
40 ms |
12804 KB |
Output is correct |
14 |
Correct |
5 ms |
5844 KB |
Output is correct |
15 |
Correct |
5 ms |
5972 KB |
Output is correct |
16 |
Correct |
173 ms |
24024 KB |
Output is correct |
17 |
Correct |
3 ms |
5692 KB |
Output is correct |
18 |
Correct |
3 ms |
5716 KB |
Output is correct |
19 |
Correct |
4 ms |
5716 KB |
Output is correct |
20 |
Correct |
3 ms |
5716 KB |
Output is correct |
21 |
Correct |
4 ms |
5716 KB |
Output is correct |
22 |
Correct |
3 ms |
5716 KB |
Output is correct |
23 |
Correct |
396 ms |
40288 KB |
Output is correct |
24 |
Correct |
3 ms |
5716 KB |
Output is correct |
25 |
Correct |
5 ms |
5972 KB |
Output is correct |
26 |
Correct |
5 ms |
6100 KB |
Output is correct |
27 |
Correct |
6 ms |
6228 KB |
Output is correct |
28 |
Correct |
143 ms |
19764 KB |
Output is correct |
29 |
Correct |
199 ms |
26068 KB |
Output is correct |
30 |
Correct |
297 ms |
34012 KB |
Output is correct |
31 |
Correct |
381 ms |
40184 KB |
Output is correct |
32 |
Correct |
4 ms |
5716 KB |
Output is correct |
33 |
Correct |
4 ms |
5716 KB |
Output is correct |
34 |
Correct |
4 ms |
5716 KB |
Output is correct |
35 |
Correct |
3 ms |
5716 KB |
Output is correct |
36 |
Correct |
4 ms |
5716 KB |
Output is correct |
37 |
Correct |
3 ms |
5716 KB |
Output is correct |
38 |
Correct |
3 ms |
5692 KB |
Output is correct |
39 |
Correct |
4 ms |
5716 KB |
Output is correct |
40 |
Correct |
4 ms |
5716 KB |
Output is correct |
41 |
Correct |
3 ms |
5716 KB |
Output is correct |
42 |
Correct |
4 ms |
5716 KB |
Output is correct |
43 |
Correct |
5 ms |
5972 KB |
Output is correct |
44 |
Correct |
6 ms |
6232 KB |
Output is correct |
45 |
Correct |
157 ms |
22940 KB |
Output is correct |
46 |
Correct |
260 ms |
31636 KB |
Output is correct |
47 |
Correct |
254 ms |
31620 KB |
Output is correct |
48 |
Incorrect |
4 ms |
5716 KB |
Tree (a[1], b[1]) = (3, 1) is not adjacent to edge between u[1]=0 @(6, 2) and v[1]=1 @(4, 2) |
49 |
Halted |
0 ms |
0 KB |
- |