#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
int construct_roads(vector<int> x, vector<int> y) {
if (x.size() == 1) {
build({}, {}, {}, {});
return 1;
}
map<pair<int, int>, int> mp;
vector<int> u, v, a, b;
vector<pair<int, int>> e;
int n = (int)x.size();
for(int i = 0; i < n; i++){
if(mp.count({x[i], y[i] - 2})){
e.push_back({mp[{x[i], y[i] - 2}], i});
}
if(mp.count({x[i], y[i] + 2})){
e.push_back({mp[{x[i], y[i] + 2}], i});
}
if(mp.count({x[i] - 2, y[i]})){
e.push_back({mp[{x[i] - 2, y[i]}], i});
}
if(mp.count({x[i] + 2, y[i]})){
e.push_back({mp[{x[i] + 2, y[i]}], i});
}
mp[{x[i], y[i]}] = i;
}
vector<int> par(n, -1);
function<int(int)> getpar = [&](int x){
return (par[x] < 0 ? x : par[x] = getpar(par[x]));
};
auto mrg = [&](int x, int y){
x = getpar(x), y = getpar(y);
if(x == y)return false;
if(par[x] > par[y])swap(x, y);
par[x] += par[y], par[y] = x;
return true;
};
for(auto [i, j]: e){
if(mrg(i, j)){
u.push_back(i), v.push_back(j);
a.push_back((x[i] != x[j] ? 3 : (x[i] == 2 ? 1 : 5)));
b.push_back(max(y[i], y[j]) - 1);
}
}
int cnt = 0;
for(int i = 0; i < n; i++)cnt += par[i] < 0;
if(cnt > 1)return 0;
build(u, v, a, b);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 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 |
124 ms |
15620 KB |
Output is correct |
10 |
Correct |
8 ms |
2056 KB |
Output is correct |
11 |
Correct |
42 ms |
8580 KB |
Output is correct |
12 |
Correct |
13 ms |
3040 KB |
Output is correct |
13 |
Correct |
29 ms |
5924 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
452 KB |
Output is correct |
16 |
Correct |
109 ms |
15716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 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 |
124 ms |
15620 KB |
Output is correct |
10 |
Correct |
8 ms |
2056 KB |
Output is correct |
11 |
Correct |
42 ms |
8580 KB |
Output is correct |
12 |
Correct |
13 ms |
3040 KB |
Output is correct |
13 |
Correct |
29 ms |
5924 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
452 KB |
Output is correct |
16 |
Correct |
109 ms |
15716 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
392 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
286 ms |
31332 KB |
Output is correct |
24 |
Correct |
0 ms |
600 KB |
Output is correct |
25 |
Correct |
2 ms |
856 KB |
Output is correct |
26 |
Correct |
3 ms |
736 KB |
Output is correct |
27 |
Correct |
3 ms |
860 KB |
Output is correct |
28 |
Correct |
105 ms |
12720 KB |
Output is correct |
29 |
Correct |
173 ms |
18556 KB |
Output is correct |
30 |
Correct |
240 ms |
25776 KB |
Output is correct |
31 |
Correct |
330 ms |
32308 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 |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
436 KB |
Output is correct |
36 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
440 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
448 KB |
Output is correct |
44 |
Correct |
3 ms |
604 KB |
Output is correct |
45 |
Correct |
142 ms |
15764 KB |
Output is correct |
46 |
Correct |
186 ms |
23508 KB |
Output is correct |
47 |
Correct |
198 ms |
23520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 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 |
124 ms |
15620 KB |
Output is correct |
10 |
Correct |
8 ms |
2056 KB |
Output is correct |
11 |
Correct |
42 ms |
8580 KB |
Output is correct |
12 |
Correct |
13 ms |
3040 KB |
Output is correct |
13 |
Correct |
29 ms |
5924 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
452 KB |
Output is correct |
16 |
Correct |
109 ms |
15716 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
392 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
286 ms |
31332 KB |
Output is correct |
24 |
Correct |
0 ms |
600 KB |
Output is correct |
25 |
Correct |
2 ms |
856 KB |
Output is correct |
26 |
Correct |
3 ms |
736 KB |
Output is correct |
27 |
Correct |
3 ms |
860 KB |
Output is correct |
28 |
Correct |
105 ms |
12720 KB |
Output is correct |
29 |
Correct |
173 ms |
18556 KB |
Output is correct |
30 |
Correct |
240 ms |
25776 KB |
Output is correct |
31 |
Correct |
330 ms |
32308 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 |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
436 KB |
Output is correct |
36 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
440 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
448 KB |
Output is correct |
44 |
Correct |
3 ms |
604 KB |
Output is correct |
45 |
Correct |
142 ms |
15764 KB |
Output is correct |
46 |
Correct |
186 ms |
23508 KB |
Output is correct |
47 |
Correct |
198 ms |
23520 KB |
Output is correct |
48 |
Incorrect |
0 ms |
348 KB |
Tree (a[0], b[0]) = (3, 1) is not adjacent to edge between u[0]=0 @(6, 2) and v[0]=1 @(4, 2) |
49 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 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 |
124 ms |
15620 KB |
Output is correct |
10 |
Correct |
8 ms |
2056 KB |
Output is correct |
11 |
Correct |
42 ms |
8580 KB |
Output is correct |
12 |
Correct |
13 ms |
3040 KB |
Output is correct |
13 |
Correct |
29 ms |
5924 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
452 KB |
Output is correct |
16 |
Correct |
109 ms |
15716 KB |
Output is correct |
17 |
Incorrect |
0 ms |
348 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 |
344 KB |
Output is correct |
2 |
Correct |
0 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 |
124 ms |
15620 KB |
Output is correct |
10 |
Correct |
8 ms |
2056 KB |
Output is correct |
11 |
Correct |
42 ms |
8580 KB |
Output is correct |
12 |
Correct |
13 ms |
3040 KB |
Output is correct |
13 |
Correct |
29 ms |
5924 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
452 KB |
Output is correct |
16 |
Correct |
109 ms |
15716 KB |
Output is correct |
17 |
Incorrect |
237 ms |
31472 KB |
Tree (a[0], b[0]) = (3, 100001) is not adjacent to edge between u[0]=12 @(47872, 100002) and v[0]=171 @(47874, 100002) |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 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 |
124 ms |
15620 KB |
Output is correct |
10 |
Correct |
8 ms |
2056 KB |
Output is correct |
11 |
Correct |
42 ms |
8580 KB |
Output is correct |
12 |
Correct |
13 ms |
3040 KB |
Output is correct |
13 |
Correct |
29 ms |
5924 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
452 KB |
Output is correct |
16 |
Correct |
109 ms |
15716 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
392 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
286 ms |
31332 KB |
Output is correct |
24 |
Correct |
0 ms |
600 KB |
Output is correct |
25 |
Correct |
2 ms |
856 KB |
Output is correct |
26 |
Correct |
3 ms |
736 KB |
Output is correct |
27 |
Correct |
3 ms |
860 KB |
Output is correct |
28 |
Correct |
105 ms |
12720 KB |
Output is correct |
29 |
Correct |
173 ms |
18556 KB |
Output is correct |
30 |
Correct |
240 ms |
25776 KB |
Output is correct |
31 |
Correct |
330 ms |
32308 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 |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
436 KB |
Output is correct |
36 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
440 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
448 KB |
Output is correct |
44 |
Correct |
3 ms |
604 KB |
Output is correct |
45 |
Correct |
142 ms |
15764 KB |
Output is correct |
46 |
Correct |
186 ms |
23508 KB |
Output is correct |
47 |
Correct |
198 ms |
23520 KB |
Output is correct |
48 |
Incorrect |
0 ms |
348 KB |
Tree (a[0], b[0]) = (3, 1) is not adjacent to edge between u[0]=0 @(6, 2) and v[0]=1 @(4, 2) |
49 |
Halted |
0 ms |
0 KB |
- |