/*
Mayoeba Yabureru
*/
//#include "parks.h"
#include<bits/stdc++.h>
using namespace std;
static vector<int> _u, _v, _a, _b;
void build(vector<int> u, vector<int> v, vector<int> a, vector<int> b) {
_u = u;
_v = v;
_a = a;
_b = b;
}
int construct_roads(vector<int> x, vector<int> y) {
int n = x.size();
vector<vector<int>> gr(n + 1);
vector<int> dsu(n + 1);
map<pair<int, int>, int> mp;
map<pair<int, int>, pair<int, int>> mpp;
vector<pair<int, int>> vv;
x.insert(x.begin(), 0);
y.insert(y.begin(), 0);
for (int i = 1; i <= n; i ++) {
mp[{x[i], y[i]}] = i;
vv.push_back({x[i], y[i]});
dsu[i] = i;
}
vector<int> u, v, a, b;
map<pair<int, int>, int> taken;
map<pair<int, int>, int> connected;
function<int(int)> fp = [&](int x) {
if (dsu[x] == x) return x;
return dsu[x] = fp(dsu[x]);
};
function cmp = [&] (pair<int, int> a, pair<int, int> b) {
if (a.first + a.second < b.first + b.second) return 1;
return 0;
};
sort(vv.begin(), vv.end(), cmp);
for (int i = 0; i < n; i ++) {
vector nx = {0, 0}, ny = {2, -2};
for (int j = 0; j < 4; j ++) {
auto xx = make_pair(vv[i].first + nx[j], vv[i].second + ny[j]);
if (mp[xx]) {
int fx = fp(mp[vv[i]]), fy = fp(mp[xx]);
if (fx != fy) {
if (vv[i].first < xx.first || vv[i].second < xx.second) {
u.push_back(mp[vv[i]]);
v.push_back(mp[xx]);
}
else {
v.push_back(mp[vv[i]]);
u.push_back(mp[xx]);
}
gr[mp[vv[i]]].push_back(mp[xx]);
gr[mp[xx]].push_back(mp[vv[i]]);
dsu[fx] = fy;
connected[{mp[vv[i]], mp[xx]}] = 1;
connected[{mp[xx], mp[vv[i]]}] = 1;
}
}
}
}
for (int i = 0; i < n; i ++) {
vector nx = {2, -2}, ny = {0, 0};
for (int j = 0; j < 4; j ++) {
auto xx = make_pair(vv[i].first + nx[j], vv[i].second + ny[j]);
if (mp[xx]) {
int fx = fp(mp[vv[i]]), fy = fp(mp[xx]);
if (fx != fy) {
if (vv[i].first < xx.first || vv[i].second < xx.second) {
u.push_back(mp[vv[i]]);
v.push_back(mp[xx]);
}
else {
v.push_back(mp[vv[i]]);
u.push_back(mp[xx]);
}
gr[mp[vv[i]]].push_back(mp[xx]);
gr[mp[xx]].push_back(mp[vv[i]]);
dsu[fx] = fy;
connected[{mp[vv[i]], mp[xx]}] = 1;
connected[{mp[xx], mp[vv[i]]}] = 1;
}
}
}
}
int num = 0, st = 1;
vector<int> vis(n + 1);
for (int i = 1; i <= n; i ++) {
if (mp[{x[i], y[i] + 2}]) {
st = i;
break;
}
}
function<void(int)> go = [&] (int v) {
num ++;
vis[v] = 1;
vector nx = {0, 2, 0, -2}, ny = {2, 0, -2, 0};
int ii = 0;
for (int i = 0; i < 4; i ++) {
int u = mp[{x[v] + nx[i], y[v] + ny[i]}];
if (u == 0) continue;
if (vis[u]) {
ii = (i + 1) % 4;
break;
}
}
int nummmm = 10;
while (nummmm --) {
int i = ii;
ii = (ii + 1) % 4;
int u = mp[{x[v] + nx[i], y[v] + ny[i]}];
if (u == 0 || vis[u] || connected[{u, v}] == 0) continue;
if (x[v] != x[u]) {
int xx = v, uu = u;
if (x[xx] > x[uu]) {
int ad = y[uu] % 4;
if (ad == 2) ad = 1;
else ad = -1;
if (taken[{x[uu] + 1, y[uu] + ad}] == 0) {
mpp[{uu, xx}] = {x[uu] + 1, y[uu] + ad};
taken[{x[uu] + 1, y[uu] + ad}] = 1;
}
else if (taken[{x[uu] + 1, y[uu] - ad}] == 0) {
mpp[{uu, xx}] = {x[uu] + 1, y[uu] - ad};
taken[{x[uu] + 1, y[uu] - ad}] = 1;
}
else assert(0);
}
else {
int ad = y[xx] % 4;
if (ad == 2) ad = 1;
else ad = -1;
if (taken[{x[xx] + 1, y[xx] - ad}] == 0) {
mpp[{xx, uu}] = {x[xx] + 1, y[xx] - ad};
taken[{x[xx] + 1, y[xx] - ad}] = 1;
}
else if (taken[{x[xx] + 1, y[xx] + ad}] == 0) {
mpp[{xx, uu}] = {x[xx] + 1, y[xx] + ad};
taken[{x[xx] + 1, y[xx] + ad}] = 1;
}
else assert(0);
}
}
else {
int xx = v, uu = u;
if (y[xx] > y[uu]) {
int ad = y[uu] % 4;
if (ad == 2) ad = 1;
else ad = -1;
if (taken[{x[uu] + ad, y[uu] + 1}] == 0) {
mpp[{uu, xx}] = {x[uu] + ad, y[uu] + 1};
taken[{x[uu] + ad, y[uu] + 1}] = 1;
}
else if (taken[{x[uu] - ad, y[uu] + 1}] == 0) {
mpp[{uu, xx}] = {x[uu] - ad, y[uu] + 1};
taken[{x[uu] - ad, y[uu] + 1}] = 1;
}
else assert(0);
}
else {
int ad = y[xx] % 4;
if (ad == 2) ad = 1;
else ad = -1;
if (taken[{x[xx] - ad, y[xx] + 1}] == 0) {
mpp[{xx, uu}] = {x[xx] - ad, y[xx] + 1};
taken[{x[xx] - ad, y[xx] + 1}] = 1;
}
else if (taken[{x[xx] + ad, y[xx] + 1}] == 0) {
mpp[{xx, uu}] = {x[xx] + ad, y[xx] + 1};
taken[{x[xx] + ad, y[xx] + 1}] = 1;
}
else assert(0);
}
}
go(u);
}
};
go(st);
for (int i = 0; i < u.size(); i ++) {
a.push_back(mpp[{u[i], v[i]}].first);
b.push_back(mpp[{u[i], v[i]}].second);
u[i] --;
v[i] --;
}
if (num == n) {
build(u, v, a, b);
return 1;
}
return 0;
}
int main() {
int n = 10000;
assert(scanf("%d", &n) == 1);
vector<int> x(n), y(n);
for (int i = 0; i < n; i++) assert(scanf("%d%d", &x[i], &y[i]) == 2);
const int possible = construct_roads(x, y);
printf("%d\n", possible);
if (possible == 1) {
int m = _u.size();
printf("%d\n", m);
for (int j = 0; j < m; j++) {
printf("%d %d %d %d\n", _u[j], _v[j], _a[j], _b[j]);
}
}
}
Compilation message
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:186:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
186 | for (int i = 0; i < u.size(); i ++) {
| ~~^~~~~~~~~~
/usr/bin/ld: /tmp/ccmcMjFw.o: in function `build(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)':
grader.cpp:(.text+0x270): multiple definition of `build(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'; /tmp/ccQrTyKx.o:parks.cpp:(.text+0x6b0): first defined here
/usr/bin/ld: /tmp/ccmcMjFw.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccQrTyKx.o:parks.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status