#include "parks.h"
#include <bits/stdc++.h>
#define s second
#define f first
using namespace std;
typedef vector <int> vi;
typedef pair<int, int> ii;
typedef pair<ii, ii> iiii;
typedef vector<ii> vii;
typedef map <pair<int,int>, int > mpair;
mpair mp, match1;
vi u, v, a, b;
vii match2;
iiii find(int t, vi x, vi y){
ii c, d;
iiii e;
int i = u[t], j = v[t];
if(x[i]==x[j]){
c = {x[i]+1, (y[i]+y[j])/2};
d = {x[i]-1, (y[i]+y[j])/2};
e = {c, d};
return (e);
}
else{
c = {(x[i]+x[j])/2, y[i]+1};
d = {(x[i]+x[j])/2, y[i]-1};
e = {c, d};
return (e);
}
}
int matching(int t, vi x, vi y){
iiii retur;
ii op1, op2;
retur = find(t, x, y);
op1 = retur.f;
op2 = retur.s;
if(!match1[op1]){
match1[op1] = t+1;
match2[t] = op1;
return 1;
}
else if(!match1[op2]){
match1[op2] = t+1;
match2[t] = op2;
return 1;
}
else{
if((match1[op1] != t+1) && (match1[op2] != t+1)){
return 0;
}
if(match1[op2]==t+1) swap(op1, op2);
if(matching(match1[op2]-1, x, y)){
match1[op2] = t+1;
match2[t] = op2;
return 1;
}
}
}
int maskx[4], masky[4];
int construct_roads(vi x, vi y){
maskx[1] = 2; maskx[3] = -2;
masky[0] = 2; masky[2] = -2;
int n = x.size(), i, f, j;
match2 = vii(n, {-1, -1});
for(i=0;i<n;i++){
mp[{x[i], y[i]}] = i+1;
}
for(i=0;i<n;i++){
for(j=0;j<4;j++){
f = mp[{x[i]+maskx[j], y[i]+masky[j]}];
if(f>i+1){
f--;
u.push_back(i);
v.push_back(f);
}
}
}
for(i=0;i<u.size();i++){
if(!matching(i, x, y)) return 0;
}
for(i=0;i<u.size();i++){
a.push_back(match2[i].f);
b.push_back(match2[i].s);
}
build(u, v, a, b);
return 1;
}
Compilation message
parks.cpp: In function 'int construct_roads(vi, vi)':
parks.cpp:85:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for(i=0;i<u.size();i++){
| ~^~~~~~~~~
parks.cpp:88:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for(i=0;i<u.size();i++){
| ~^~~~~~~~~
parks.cpp: In function 'int matching(int, vi, vi)':
parks.cpp:63:1: warning: control reaches end of non-void function [-Wreturn-type]
63 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Given structure is not connected: There is no path between vertices 0 and 1 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Given structure is not connected: There is no path between vertices 0 and 1 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Given structure is not connected: There is no path between vertices 0 and 1 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Given structure is not connected: There is no path between vertices 0 and 1 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Given structure is not connected: There is no path between vertices 0 and 1 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Given structure is not connected: There is no path between vertices 0 and 1 |
4 |
Halted |
0 ms |
0 KB |
- |