#include "parks.h"
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename t>
using matrix = vector<vector<t>>;
int construct_roads(std::vector<int> x, std::vector<int> y) {
if (x.size() == 1) {
build({}, {}, {}, {});
return 1;
}
int n = x.size();
std::vector<int> u, v, a(n-1), b(n-1);
int dx[]{1,0,-1,0};
int dy[]{0,1,0,-1};
vector<int> pai(n);
int comp = n;
iota(all(pai),0);
auto find =[&](int id, auto f){
if(pai[id] == id)
return id;
return pai[id] = f(pai[id],f);
};
auto onion =[&](int a, int b){
int pa = find(a,find);
int pb = find(b,find);
if(pa != pb){
comp--;
u.push_back(a);
v.push_back(b);
}
pai[pa] = pb;
};
map<pii,int> fount;
for(int i = 0; i < n; i++)
fount[{x[i],y[i]}] = i;
for(int i = 0; i < n; i++){
for(int j = 0; j < 4; j++){
int xi = x[i] + dx[j]*2, yi = y[i]+dy[j]*2;
if(fount.count({xi,yi}))
onion(i,fount[{xi,yi}]);
}
}
if(comp > 1)
return 0;
set<pii> bench;
mt19937 rng(time(nullptr));
vector<int>o(n-1);
iota(all(o),0);
shuffle(all(o),rng);
for(int i : o){
int cx = (x[u[i]]+x[v[i]])>>1, cy = (y[u[i]]+y[v[i]])>>1;
bool ok = 0;
for(int j = 0; j < 4; j++){
int xi = cx + dx[j], yi = cy+dy[j];
if(!((xi&1)&&(yi&1)))
continue;
if(!bench.count({xi,yi})){
a[i] = xi;
b[i] =yi;
bench.insert({xi,yi});
ok = 1;
break;
}
}
if(!ok)
return 0;
}
build(u,v,a,b);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
216 ms |
18284 KB |
Output is correct |
10 |
Correct |
14 ms |
2260 KB |
Output is correct |
11 |
Correct |
87 ms |
9948 KB |
Output is correct |
12 |
Correct |
20 ms |
3156 KB |
Output is correct |
13 |
Correct |
38 ms |
4808 KB |
Output is correct |
14 |
Correct |
1 ms |
400 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
267 ms |
18356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
216 ms |
18284 KB |
Output is correct |
10 |
Correct |
14 ms |
2260 KB |
Output is correct |
11 |
Correct |
87 ms |
9948 KB |
Output is correct |
12 |
Correct |
20 ms |
3156 KB |
Output is correct |
13 |
Correct |
38 ms |
4808 KB |
Output is correct |
14 |
Correct |
1 ms |
400 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
267 ms |
18356 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
304 KB |
Output is correct |
23 |
Incorrect |
572 ms |
22660 KB |
Solution announced impossible, but it is possible. |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
216 ms |
18284 KB |
Output is correct |
10 |
Correct |
14 ms |
2260 KB |
Output is correct |
11 |
Correct |
87 ms |
9948 KB |
Output is correct |
12 |
Correct |
20 ms |
3156 KB |
Output is correct |
13 |
Correct |
38 ms |
4808 KB |
Output is correct |
14 |
Correct |
1 ms |
400 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
267 ms |
18356 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
304 KB |
Output is correct |
23 |
Incorrect |
572 ms |
22660 KB |
Solution announced impossible, but it is possible. |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
216 ms |
18284 KB |
Output is correct |
10 |
Correct |
14 ms |
2260 KB |
Output is correct |
11 |
Correct |
87 ms |
9948 KB |
Output is correct |
12 |
Correct |
20 ms |
3156 KB |
Output is correct |
13 |
Correct |
38 ms |
4808 KB |
Output is correct |
14 |
Correct |
1 ms |
400 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
267 ms |
18356 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Incorrect |
524 ms |
21392 KB |
Solution announced impossible, but it is possible. |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
216 ms |
18284 KB |
Output is correct |
10 |
Correct |
14 ms |
2260 KB |
Output is correct |
11 |
Correct |
87 ms |
9948 KB |
Output is correct |
12 |
Correct |
20 ms |
3156 KB |
Output is correct |
13 |
Correct |
38 ms |
4808 KB |
Output is correct |
14 |
Correct |
1 ms |
400 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
267 ms |
18356 KB |
Output is correct |
17 |
Correct |
669 ms |
36336 KB |
Output is correct |
18 |
Incorrect |
545 ms |
27512 KB |
Solution announced impossible, but it is possible. |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
216 ms |
18284 KB |
Output is correct |
10 |
Correct |
14 ms |
2260 KB |
Output is correct |
11 |
Correct |
87 ms |
9948 KB |
Output is correct |
12 |
Correct |
20 ms |
3156 KB |
Output is correct |
13 |
Correct |
38 ms |
4808 KB |
Output is correct |
14 |
Correct |
1 ms |
400 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
267 ms |
18356 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
304 KB |
Output is correct |
23 |
Incorrect |
572 ms |
22660 KB |
Solution announced impossible, but it is possible. |
24 |
Halted |
0 ms |
0 KB |
- |