#include "parks.h"
#include "bits/stdc++.h"
using namespace std;
#ifndef EVAL
#include "grader.cpp"
#endif
#define ar array
typedef long long ll;
const int N = 2e5 + 5;
vector<ar<int, 3>> edges[N];
int construct_roads(vector<int> x, vector<int> y) {
int n = x.size();
map<ar<int, 2>, int> ss, mm;
for(int i=0;i<n;i++){
ss[{x[i], y[i]}] = i;
}
vector<ar<int, 2>> e, p;
auto add = [&](int a, int b, int p1, int p2){
edges[a].push_back({b, p1, p2});
edges[b].push_back({a, p1, p2});
};
for(int i=0;i<n;i++){
if(ss.count({x[i] - 2, y[i]})){
int j = ss[{x[i] - 2, y[i]}];
e.push_back({i, j});
p.push_back({-1, -1});
int u = e.size() - 1;
if(mm.count({x[i] - 1, y[i] - 1})){
int v = mm[{x[i] - 1, y[i] - 1}];
add(u, v, x[i] - 1, y[i] - 1);
mm.erase({x[i] - 1, y[i] - 1});
} else {
mm[{x[i] - 1, y[i] - 1}] = u;
}
if(mm.count({x[i] - 1, y[i] + 1})){
int v = mm[{x[i] - 1, y[i] + 1}];
add(u, v, x[i] - 1, y[i] + 1);
mm.erase({x[i] - 1, y[i] + 1});
} else {
mm[{x[i] - 1, y[i] + 1}] = u;
}
}
if(ss.count({x[i], y[i] - 2})){
int j = ss[{x[i], y[i] - 2}];
e.push_back({i, j});
p.push_back({-1, -1});
int u = e.size() - 1;
if(mm.count({x[i] - 1, y[i] - 1})){
int v = mm[{x[i] - 1, y[i] - 1}];
add(u, v, x[i] - 1, y[i] - 1);
mm.erase({x[i] - 1, y[i] - 1});
} else {
mm[{x[i] - 1, y[i] - 1}] = u;
}
if(mm.count({x[i] + 1, y[i] - 1})){
int v = mm[{x[i] + 1, y[i] - 1}];
add(u, v, x[i] + 1, y[i] - 1);
mm.erase({x[i] + 1, y[i] - 1});
} else {
mm[{x[i] + 1, y[i] - 1}] = u;
}
}
}
int m = e.size();
if(m < n - 1) return 0;
assert(m == n - 1);
for(int i=0;i<m;i++){
assert((int)edges[i].size() <= 2);
}
vector<int> used(m);
function<void(int)> dfs = [&](int i){
used[i] = 1;
for(auto [x, p1, p2] : edges[i]){
if(used[x]) continue;
p[x] = {p1, p2};
dfs(x);
}
};
for(auto [x, i] : mm){
if(used[i]) continue;
p[i] = x;
dfs(i);
}
for(int i=0;i<m;i++){
if(used[i]) continue;
p[i] = {edges[i].back()[1], edges[i].back()[2]};
edges[i].pop_back();
dfs(i);
}
vector<int> u(m), v(m), A(m), B(m);
for(int i=0;i<m;i++){
u[i] = e[i][0], v[i] = e[i][1];
A[i] = p[i][0], B[i] = p[i][1];
assert(~A[i] && ~B[i]);
}
build(u, v, A, B);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
5000 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4932 KB |
Output is correct |
9 |
Correct |
310 ms |
31996 KB |
Output is correct |
10 |
Correct |
17 ms |
7732 KB |
Output is correct |
11 |
Correct |
105 ms |
19508 KB |
Output is correct |
12 |
Correct |
26 ms |
9060 KB |
Output is correct |
13 |
Correct |
72 ms |
14648 KB |
Output is correct |
14 |
Correct |
4 ms |
5204 KB |
Output is correct |
15 |
Correct |
5 ms |
5332 KB |
Output is correct |
16 |
Correct |
304 ms |
32004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
5000 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4932 KB |
Output is correct |
9 |
Correct |
310 ms |
31996 KB |
Output is correct |
10 |
Correct |
17 ms |
7732 KB |
Output is correct |
11 |
Correct |
105 ms |
19508 KB |
Output is correct |
12 |
Correct |
26 ms |
9060 KB |
Output is correct |
13 |
Correct |
72 ms |
14648 KB |
Output is correct |
14 |
Correct |
4 ms |
5204 KB |
Output is correct |
15 |
Correct |
5 ms |
5332 KB |
Output is correct |
16 |
Correct |
304 ms |
32004 KB |
Output is correct |
17 |
Runtime error |
7 ms |
9940 KB |
Execution killed with signal 6 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
5000 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4932 KB |
Output is correct |
9 |
Correct |
310 ms |
31996 KB |
Output is correct |
10 |
Correct |
17 ms |
7732 KB |
Output is correct |
11 |
Correct |
105 ms |
19508 KB |
Output is correct |
12 |
Correct |
26 ms |
9060 KB |
Output is correct |
13 |
Correct |
72 ms |
14648 KB |
Output is correct |
14 |
Correct |
4 ms |
5204 KB |
Output is correct |
15 |
Correct |
5 ms |
5332 KB |
Output is correct |
16 |
Correct |
304 ms |
32004 KB |
Output is correct |
17 |
Runtime error |
7 ms |
9940 KB |
Execution killed with signal 6 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
5000 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4932 KB |
Output is correct |
9 |
Correct |
310 ms |
31996 KB |
Output is correct |
10 |
Correct |
17 ms |
7732 KB |
Output is correct |
11 |
Correct |
105 ms |
19508 KB |
Output is correct |
12 |
Correct |
26 ms |
9060 KB |
Output is correct |
13 |
Correct |
72 ms |
14648 KB |
Output is correct |
14 |
Correct |
4 ms |
5204 KB |
Output is correct |
15 |
Correct |
5 ms |
5332 KB |
Output is correct |
16 |
Correct |
304 ms |
32004 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4952 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
20 |
Correct |
694 ms |
54104 KB |
Output is correct |
21 |
Correct |
853 ms |
49812 KB |
Output is correct |
22 |
Correct |
678 ms |
47556 KB |
Output is correct |
23 |
Correct |
651 ms |
50872 KB |
Output is correct |
24 |
Correct |
281 ms |
20648 KB |
Output is correct |
25 |
Correct |
725 ms |
48696 KB |
Output is correct |
26 |
Correct |
734 ms |
48676 KB |
Output is correct |
27 |
Correct |
813 ms |
58892 KB |
Output is correct |
28 |
Correct |
822 ms |
58976 KB |
Output is correct |
29 |
Correct |
851 ms |
58876 KB |
Output is correct |
30 |
Correct |
810 ms |
58900 KB |
Output is correct |
31 |
Correct |
2 ms |
4948 KB |
Output is correct |
32 |
Correct |
35 ms |
8052 KB |
Output is correct |
33 |
Correct |
92 ms |
12736 KB |
Output is correct |
34 |
Correct |
776 ms |
56312 KB |
Output is correct |
35 |
Correct |
20 ms |
6612 KB |
Output is correct |
36 |
Correct |
113 ms |
12348 KB |
Output is correct |
37 |
Correct |
294 ms |
19996 KB |
Output is correct |
38 |
Correct |
270 ms |
21200 KB |
Output is correct |
39 |
Correct |
463 ms |
27056 KB |
Output is correct |
40 |
Correct |
525 ms |
33280 KB |
Output is correct |
41 |
Correct |
693 ms |
39252 KB |
Output is correct |
42 |
Correct |
889 ms |
45412 KB |
Output is correct |
43 |
Correct |
2 ms |
4948 KB |
Output is correct |
44 |
Correct |
3 ms |
4948 KB |
Output is correct |
45 |
Correct |
2 ms |
4948 KB |
Output is correct |
46 |
Correct |
3 ms |
4948 KB |
Output is correct |
47 |
Correct |
4 ms |
4948 KB |
Output is correct |
48 |
Correct |
3 ms |
4976 KB |
Output is correct |
49 |
Correct |
3 ms |
4948 KB |
Output is correct |
50 |
Correct |
2 ms |
4948 KB |
Output is correct |
51 |
Correct |
2 ms |
4948 KB |
Output is correct |
52 |
Correct |
2 ms |
4928 KB |
Output is correct |
53 |
Correct |
3 ms |
4948 KB |
Output is correct |
54 |
Correct |
5 ms |
5332 KB |
Output is correct |
55 |
Correct |
7 ms |
5460 KB |
Output is correct |
56 |
Correct |
357 ms |
27044 KB |
Output is correct |
57 |
Correct |
561 ms |
37328 KB |
Output is correct |
58 |
Correct |
595 ms |
37100 KB |
Output is correct |
59 |
Correct |
2 ms |
4948 KB |
Output is correct |
60 |
Correct |
4 ms |
4948 KB |
Output is correct |
61 |
Correct |
3 ms |
4948 KB |
Output is correct |
62 |
Correct |
756 ms |
58996 KB |
Output is correct |
63 |
Correct |
802 ms |
58968 KB |
Output is correct |
64 |
Correct |
786 ms |
58800 KB |
Output is correct |
65 |
Correct |
10 ms |
5588 KB |
Output is correct |
66 |
Correct |
16 ms |
6228 KB |
Output is correct |
67 |
Correct |
332 ms |
26300 KB |
Output is correct |
68 |
Correct |
591 ms |
37020 KB |
Output is correct |
69 |
Correct |
829 ms |
47824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
5000 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4932 KB |
Output is correct |
9 |
Correct |
310 ms |
31996 KB |
Output is correct |
10 |
Correct |
17 ms |
7732 KB |
Output is correct |
11 |
Correct |
105 ms |
19508 KB |
Output is correct |
12 |
Correct |
26 ms |
9060 KB |
Output is correct |
13 |
Correct |
72 ms |
14648 KB |
Output is correct |
14 |
Correct |
4 ms |
5204 KB |
Output is correct |
15 |
Correct |
5 ms |
5332 KB |
Output is correct |
16 |
Correct |
304 ms |
32004 KB |
Output is correct |
17 |
Runtime error |
602 ms |
98832 KB |
Execution killed with signal 6 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
5000 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4932 KB |
Output is correct |
9 |
Correct |
310 ms |
31996 KB |
Output is correct |
10 |
Correct |
17 ms |
7732 KB |
Output is correct |
11 |
Correct |
105 ms |
19508 KB |
Output is correct |
12 |
Correct |
26 ms |
9060 KB |
Output is correct |
13 |
Correct |
72 ms |
14648 KB |
Output is correct |
14 |
Correct |
4 ms |
5204 KB |
Output is correct |
15 |
Correct |
5 ms |
5332 KB |
Output is correct |
16 |
Correct |
304 ms |
32004 KB |
Output is correct |
17 |
Runtime error |
7 ms |
9940 KB |
Execution killed with signal 6 |
18 |
Halted |
0 ms |
0 KB |
- |