#include <bits/stdc++.h>
#include "parks.h"
using namespace std;
int construct_roads(vector<int> xs, vector<int> ys) {
int n = xs.size();
map<pair<int, int>, int> points;
for (int i = 0; i < n; ++i)
points[make_pair(xs[i], ys[i])] = i;
vector<int> rep(n); int comps = n;
for (int i = 0; i < n; ++i)
rep[i] = i;
function<int (int)> find = [&rep, &find](int u) {
if (rep[u] == u) return u;
return rep[u] = find(rep[u]);
};
function<void (int, int)> une = [&rep, &comps, &find](int u, int v) {
u = find(u); v = find(v);
if (u == v) return;
rep[u] = v;
--comps;
};
vector<int> us, vs, as, bs;
for (int i = 0; i < n; ++i) {
int x = xs[i], y = ys[i];
if (points.find(make_pair(x + 2, y)) != points.end()) {
us.push_back(i);
vs.push_back(points[make_pair(x + 2, y)]);
une(us.back(), vs.back());
as.push_back(3);
bs.push_back(y + 1);
}
if (points.find(make_pair(x, y + 2)) != points.end()) {
us.push_back(i);
vs.push_back(points[make_pair(x, y + 2)]);
une(us.back(), vs.back());
if (x == 2) {
as.push_back(1);
bs.push_back(y + 1);
}
else {
as.push_back(5);
bs.push_back(y + 1);
}
}
}
if (comps > 1) return 0;
build(us, vs, as, bs);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
436 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
113 ms |
14124 KB |
Output is correct |
10 |
Correct |
8 ms |
1884 KB |
Output is correct |
11 |
Correct |
45 ms |
7836 KB |
Output is correct |
12 |
Correct |
11 ms |
2648 KB |
Output is correct |
13 |
Correct |
24 ms |
5332 KB |
Output is correct |
14 |
Correct |
2 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
129 ms |
14188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
436 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
113 ms |
14124 KB |
Output is correct |
10 |
Correct |
8 ms |
1884 KB |
Output is correct |
11 |
Correct |
45 ms |
7836 KB |
Output is correct |
12 |
Correct |
11 ms |
2648 KB |
Output is correct |
13 |
Correct |
24 ms |
5332 KB |
Output is correct |
14 |
Correct |
2 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
129 ms |
14188 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
366 ms |
32700 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
2 ms |
860 KB |
Output is correct |
27 |
Correct |
3 ms |
860 KB |
Output is correct |
28 |
Correct |
103 ms |
13244 KB |
Output is correct |
29 |
Correct |
169 ms |
19800 KB |
Output is correct |
30 |
Correct |
234 ms |
26288 KB |
Output is correct |
31 |
Correct |
355 ms |
32776 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
344 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
1 ms |
604 KB |
Output is correct |
44 |
Correct |
2 ms |
600 KB |
Output is correct |
45 |
Correct |
120 ms |
14224 KB |
Output is correct |
46 |
Correct |
195 ms |
20384 KB |
Output is correct |
47 |
Correct |
188 ms |
20432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
436 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
113 ms |
14124 KB |
Output is correct |
10 |
Correct |
8 ms |
1884 KB |
Output is correct |
11 |
Correct |
45 ms |
7836 KB |
Output is correct |
12 |
Correct |
11 ms |
2648 KB |
Output is correct |
13 |
Correct |
24 ms |
5332 KB |
Output is correct |
14 |
Correct |
2 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
129 ms |
14188 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
366 ms |
32700 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
2 ms |
860 KB |
Output is correct |
27 |
Correct |
3 ms |
860 KB |
Output is correct |
28 |
Correct |
103 ms |
13244 KB |
Output is correct |
29 |
Correct |
169 ms |
19800 KB |
Output is correct |
30 |
Correct |
234 ms |
26288 KB |
Output is correct |
31 |
Correct |
355 ms |
32776 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
344 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
1 ms |
604 KB |
Output is correct |
44 |
Correct |
2 ms |
600 KB |
Output is correct |
45 |
Correct |
120 ms |
14224 KB |
Output is correct |
46 |
Correct |
195 ms |
20384 KB |
Output is correct |
47 |
Correct |
188 ms |
20432 KB |
Output is correct |
48 |
Incorrect |
0 ms |
348 KB |
Tree (a[1], b[1]) = (3, 3) is not adjacent to edge between u[1]=1 @(4, 2) and v[1]=0 @(6, 2) |
49 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
436 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
113 ms |
14124 KB |
Output is correct |
10 |
Correct |
8 ms |
1884 KB |
Output is correct |
11 |
Correct |
45 ms |
7836 KB |
Output is correct |
12 |
Correct |
11 ms |
2648 KB |
Output is correct |
13 |
Correct |
24 ms |
5332 KB |
Output is correct |
14 |
Correct |
2 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
129 ms |
14188 KB |
Output is correct |
17 |
Incorrect |
1 ms |
344 KB |
Tree (a[0], b[0]) = (5, 3) is not adjacent to edge between u[0]=0 @(200000, 2) and v[0]=1 @(200000, 4) |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
436 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
113 ms |
14124 KB |
Output is correct |
10 |
Correct |
8 ms |
1884 KB |
Output is correct |
11 |
Correct |
45 ms |
7836 KB |
Output is correct |
12 |
Correct |
11 ms |
2648 KB |
Output is correct |
13 |
Correct |
24 ms |
5332 KB |
Output is correct |
14 |
Correct |
2 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
129 ms |
14188 KB |
Output is correct |
17 |
Incorrect |
291 ms |
28056 KB |
Tree (a[0], b[0]) = (3, 100003) is not adjacent to edge between u[0]=0 @(82422, 100002) and v[0]=168975 @(82424, 100002) |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
436 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
113 ms |
14124 KB |
Output is correct |
10 |
Correct |
8 ms |
1884 KB |
Output is correct |
11 |
Correct |
45 ms |
7836 KB |
Output is correct |
12 |
Correct |
11 ms |
2648 KB |
Output is correct |
13 |
Correct |
24 ms |
5332 KB |
Output is correct |
14 |
Correct |
2 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
129 ms |
14188 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
366 ms |
32700 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
2 ms |
860 KB |
Output is correct |
27 |
Correct |
3 ms |
860 KB |
Output is correct |
28 |
Correct |
103 ms |
13244 KB |
Output is correct |
29 |
Correct |
169 ms |
19800 KB |
Output is correct |
30 |
Correct |
234 ms |
26288 KB |
Output is correct |
31 |
Correct |
355 ms |
32776 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
344 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
1 ms |
604 KB |
Output is correct |
44 |
Correct |
2 ms |
600 KB |
Output is correct |
45 |
Correct |
120 ms |
14224 KB |
Output is correct |
46 |
Correct |
195 ms |
20384 KB |
Output is correct |
47 |
Correct |
188 ms |
20432 KB |
Output is correct |
48 |
Incorrect |
0 ms |
348 KB |
Tree (a[1], b[1]) = (3, 3) is not adjacent to edge between u[1]=1 @(4, 2) and v[1]=0 @(6, 2) |
49 |
Halted |
0 ms |
0 KB |
- |