#include "parks.h"
#include<bits/stdc++.h>
using namespace std;
vector<int>parent(1e6);
vector<int>siz(1e6);
void makesets(int v){
parent[v]=v;
siz[v]=1;
}
int findsets (int v){
if (v==parent[v])return v;
parent[v]=findsets(parent[v]);
return parent[v];
}
void unionset(int a,int b){
a = findsets(a);
b =findsets(b);
if (a==b)return;
if (siz[a]<siz[b])swap(a,b);
siz[a]+=siz[b];
parent[b]=a;
}
void build(vector<int> u, vector<int> v, vector<int> a, vector<int> b);
struct point {
int x,y,index;
};
bool dist(point x,point y){
if (pow(x.x - y.x,2)+pow(x.y-y.y,2)!=4)return false;
return true;
}
int construct_roads(std::vector<int> x, std::vector<int> y) {
vector<point>arr;
int n = x.size();
bool ok=true;
for (int i = 0 ;i<n;++i){
if (x[i]!=x[0])ok=false;
arr.push_back({x[i],y[i],i});
}
vector<int>ansx,ansy,ansxi,ansyi;
if (ok){
sort(arr.begin(),arr.end(),[&](point a,point b){
return a.y<b.y;
});
for (int i = 1;i<n;++i){
if (dist(arr[i],arr[i-1])){
ansx.push_back(min(arr[i].x,arr[i-1].x) + 1);
ansy.push_back(min(arr[i].y,arr[i-1].y)+1);
ansxi.push_back(arr[i].index);
ansyi.push_back(arr[i-1].index);
}
else return 0;
}
build(ansxi,ansyi,ansx,ansy);
return 1;}
else{
for (int i =0;i<n;++i){
makesets(i);
}
set<pair<int,int>>p;
sort(arr.begin(),arr.end(),[&](point a,point b){
if (a.x==b.x)return a.y<b.y;
return a.x<b.x;
});
for (int k =0;k<n;++k){
for (int j =k+1;j<n;++j){
if (dist(arr[j],arr[k])&&findsets(j)!=findsets(k)){
int first1=min(arr[k].x,arr[j].x) + 1;
int first2=min(arr[k].x,arr[j].x) + 1;
int second1=min(arr[k].y,arr[j].y) + 1;
int second2 = min(arr[k].y,arr[j].y) - 1;
if (arr[j].x==arr[k].x){
second2=min(arr[k].y,arr[j].y) + 1;
first2 = min(arr[k].x,arr[j].x) - 1;
}
else if (arr[j].y!=arr[k].y){
continue;
}
if (p.find({first1,second1})==p.end()){
ok=true;
ansx.push_back(first1);
ansy.push_back(second1);
ansxi.push_back(arr[j].index);
ansyi.push_back(arr[k].index);
unionset(j,k);
p.insert({ansx.back(),ansy.back()});
break;
}
if (p.find({first2,second1})==p.end()){
ok=true;
ansx.push_back(first2);
ansy.push_back(second1);
ansxi.push_back(arr[j].index);
ansyi.push_back(arr[k].index);
unionset(j,k);
p.insert({ansx.back(),ansy.back()});
break;
}
if (p.find({first1,second2})==p.end()){
ok=true;
ansx.push_back(first1);
ansy.push_back(second2);
ansxi.push_back(arr[j].index);
ansyi.push_back(arr[k].index);
unionset(j,k);
p.insert({ansx.back(),ansy.back()});
break;
}
if (p.find({first2,second2})==p.end()){
ok=true;
ansx.push_back(first2);
ansy.push_back(second2);
ansxi.push_back(arr[j].index);
unionset(j,k);
ansyi.push_back(arr[k].index);
p.insert({ansx.back(),ansy.back()});
break;
}
}
}
}
if (siz[findsets(0)]!=n)return 0;
build(ansxi,ansyi,ansx,ansy);
return 1;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8012 KB |
Output is correct |
3 |
Correct |
4 ms |
8012 KB |
Output is correct |
4 |
Correct |
4 ms |
8140 KB |
Output is correct |
5 |
Correct |
4 ms |
8012 KB |
Output is correct |
6 |
Correct |
4 ms |
8012 KB |
Output is correct |
7 |
Correct |
4 ms |
8012 KB |
Output is correct |
8 |
Correct |
5 ms |
8012 KB |
Output is correct |
9 |
Correct |
72 ms |
15896 KB |
Output is correct |
10 |
Correct |
10 ms |
8984 KB |
Output is correct |
11 |
Correct |
36 ms |
12232 KB |
Output is correct |
12 |
Correct |
13 ms |
9312 KB |
Output is correct |
13 |
Correct |
15 ms |
10056 KB |
Output is correct |
14 |
Correct |
6 ms |
8140 KB |
Output is correct |
15 |
Correct |
5 ms |
8140 KB |
Output is correct |
16 |
Correct |
72 ms |
15928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8012 KB |
Output is correct |
3 |
Correct |
4 ms |
8012 KB |
Output is correct |
4 |
Correct |
4 ms |
8140 KB |
Output is correct |
5 |
Correct |
4 ms |
8012 KB |
Output is correct |
6 |
Correct |
4 ms |
8012 KB |
Output is correct |
7 |
Correct |
4 ms |
8012 KB |
Output is correct |
8 |
Correct |
5 ms |
8012 KB |
Output is correct |
9 |
Correct |
72 ms |
15896 KB |
Output is correct |
10 |
Correct |
10 ms |
8984 KB |
Output is correct |
11 |
Correct |
36 ms |
12232 KB |
Output is correct |
12 |
Correct |
13 ms |
9312 KB |
Output is correct |
13 |
Correct |
15 ms |
10056 KB |
Output is correct |
14 |
Correct |
6 ms |
8140 KB |
Output is correct |
15 |
Correct |
5 ms |
8140 KB |
Output is correct |
16 |
Correct |
72 ms |
15928 KB |
Output is correct |
17 |
Correct |
4 ms |
8140 KB |
Output is correct |
18 |
Correct |
5 ms |
8012 KB |
Output is correct |
19 |
Correct |
4 ms |
8012 KB |
Output is correct |
20 |
Correct |
4 ms |
8140 KB |
Output is correct |
21 |
Correct |
6 ms |
8012 KB |
Output is correct |
22 |
Correct |
5 ms |
8012 KB |
Output is correct |
23 |
Correct |
229 ms |
33052 KB |
Output is correct |
24 |
Incorrect |
5 ms |
8012 KB |
Solution announced impossible, but it is possible. |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8012 KB |
Output is correct |
3 |
Correct |
4 ms |
8012 KB |
Output is correct |
4 |
Correct |
4 ms |
8140 KB |
Output is correct |
5 |
Correct |
4 ms |
8012 KB |
Output is correct |
6 |
Correct |
4 ms |
8012 KB |
Output is correct |
7 |
Correct |
4 ms |
8012 KB |
Output is correct |
8 |
Correct |
5 ms |
8012 KB |
Output is correct |
9 |
Correct |
72 ms |
15896 KB |
Output is correct |
10 |
Correct |
10 ms |
8984 KB |
Output is correct |
11 |
Correct |
36 ms |
12232 KB |
Output is correct |
12 |
Correct |
13 ms |
9312 KB |
Output is correct |
13 |
Correct |
15 ms |
10056 KB |
Output is correct |
14 |
Correct |
6 ms |
8140 KB |
Output is correct |
15 |
Correct |
5 ms |
8140 KB |
Output is correct |
16 |
Correct |
72 ms |
15928 KB |
Output is correct |
17 |
Correct |
4 ms |
8140 KB |
Output is correct |
18 |
Correct |
5 ms |
8012 KB |
Output is correct |
19 |
Correct |
4 ms |
8012 KB |
Output is correct |
20 |
Correct |
4 ms |
8140 KB |
Output is correct |
21 |
Correct |
6 ms |
8012 KB |
Output is correct |
22 |
Correct |
5 ms |
8012 KB |
Output is correct |
23 |
Correct |
229 ms |
33052 KB |
Output is correct |
24 |
Incorrect |
5 ms |
8012 KB |
Solution announced impossible, but it is possible. |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8012 KB |
Output is correct |
3 |
Correct |
4 ms |
8012 KB |
Output is correct |
4 |
Correct |
4 ms |
8140 KB |
Output is correct |
5 |
Correct |
4 ms |
8012 KB |
Output is correct |
6 |
Correct |
4 ms |
8012 KB |
Output is correct |
7 |
Correct |
4 ms |
8012 KB |
Output is correct |
8 |
Correct |
5 ms |
8012 KB |
Output is correct |
9 |
Correct |
72 ms |
15896 KB |
Output is correct |
10 |
Correct |
10 ms |
8984 KB |
Output is correct |
11 |
Correct |
36 ms |
12232 KB |
Output is correct |
12 |
Correct |
13 ms |
9312 KB |
Output is correct |
13 |
Correct |
15 ms |
10056 KB |
Output is correct |
14 |
Correct |
6 ms |
8140 KB |
Output is correct |
15 |
Correct |
5 ms |
8140 KB |
Output is correct |
16 |
Correct |
72 ms |
15928 KB |
Output is correct |
17 |
Correct |
5 ms |
8012 KB |
Output is correct |
18 |
Correct |
4 ms |
8084 KB |
Output is correct |
19 |
Correct |
6 ms |
8012 KB |
Output is correct |
20 |
Execution timed out |
3559 ms |
14396 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8012 KB |
Output is correct |
3 |
Correct |
4 ms |
8012 KB |
Output is correct |
4 |
Correct |
4 ms |
8140 KB |
Output is correct |
5 |
Correct |
4 ms |
8012 KB |
Output is correct |
6 |
Correct |
4 ms |
8012 KB |
Output is correct |
7 |
Correct |
4 ms |
8012 KB |
Output is correct |
8 |
Correct |
5 ms |
8012 KB |
Output is correct |
9 |
Correct |
72 ms |
15896 KB |
Output is correct |
10 |
Correct |
10 ms |
8984 KB |
Output is correct |
11 |
Correct |
36 ms |
12232 KB |
Output is correct |
12 |
Correct |
13 ms |
9312 KB |
Output is correct |
13 |
Correct |
15 ms |
10056 KB |
Output is correct |
14 |
Correct |
6 ms |
8140 KB |
Output is correct |
15 |
Correct |
5 ms |
8140 KB |
Output is correct |
16 |
Correct |
72 ms |
15928 KB |
Output is correct |
17 |
Correct |
231 ms |
33404 KB |
Output is correct |
18 |
Correct |
229 ms |
33436 KB |
Output is correct |
19 |
Execution timed out |
3572 ms |
14440 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8012 KB |
Output is correct |
3 |
Correct |
4 ms |
8012 KB |
Output is correct |
4 |
Correct |
4 ms |
8140 KB |
Output is correct |
5 |
Correct |
4 ms |
8012 KB |
Output is correct |
6 |
Correct |
4 ms |
8012 KB |
Output is correct |
7 |
Correct |
4 ms |
8012 KB |
Output is correct |
8 |
Correct |
5 ms |
8012 KB |
Output is correct |
9 |
Correct |
72 ms |
15896 KB |
Output is correct |
10 |
Correct |
10 ms |
8984 KB |
Output is correct |
11 |
Correct |
36 ms |
12232 KB |
Output is correct |
12 |
Correct |
13 ms |
9312 KB |
Output is correct |
13 |
Correct |
15 ms |
10056 KB |
Output is correct |
14 |
Correct |
6 ms |
8140 KB |
Output is correct |
15 |
Correct |
5 ms |
8140 KB |
Output is correct |
16 |
Correct |
72 ms |
15928 KB |
Output is correct |
17 |
Correct |
4 ms |
8140 KB |
Output is correct |
18 |
Correct |
5 ms |
8012 KB |
Output is correct |
19 |
Correct |
4 ms |
8012 KB |
Output is correct |
20 |
Correct |
4 ms |
8140 KB |
Output is correct |
21 |
Correct |
6 ms |
8012 KB |
Output is correct |
22 |
Correct |
5 ms |
8012 KB |
Output is correct |
23 |
Correct |
229 ms |
33052 KB |
Output is correct |
24 |
Incorrect |
5 ms |
8012 KB |
Solution announced impossible, but it is possible. |
25 |
Halted |
0 ms |
0 KB |
- |