#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
#include "parks.h"
using namespace std;
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second
const int SIZE = 2e5 + 5;
int to[SIZE], h[SIZE];
int dsu(int x) {
return x == to[x] ? x : (to[x] = dsu(to[x]));
}
void merge(int a, int b) {
a = dsu(a), b = dsu(b);
if (a == b) return;
if (h[a] < h[b]) swap(a, b);
to[b] = a;
h[a] += (h[a] == h[b]);
}
int construct_roads(vector<int> x, vector<int> y) {
int n = x.size();
map<pair<int, int>, int> mp;
FOR (i, 0, n - 1) mp[{x[i], y[i]}] = i;
vector<pair<int, int>> e;
FOR (i, 0, n - 1) {
if (mp.count({x[i] + 2, y[i]})) {
int j = mp[{x[i] + 2, y[i]}];
e.pb(i, j);
}
if (mp.count({x[i], y[i] + 2})) {
int j = mp[{x[i], y[i] + 2}];
e.pb(i, j);
}
}
sort(e.begin(), e.end(), [&](auto l, auto r) {
return make_tuple(x[l.F], x[l.S], y[l.F], y[l.S]) < make_tuple(x[r.F], x[r.S], y[r.F], y[r.S]);
});
vector<int> u, v, mx, my;
set<pair<int, int>> s;
iota(to, to + n, 0);
for (auto [a, b] : e) if (dsu(a) != dsu(b)) {
debug(a, b, x[a], y[a], x[b], y[b]);
if (x[a] == x[b]) {
int cx = x[a] + ((x[a] + y[a]) % 4 ? 1 : -1);
int cy = (y[a] + y[b]) / 2;
if (!s.count({cx, cy})) {
s.emplace(cx, cy);
merge(a, b);
u.pb(a), v.pb(b);
mx.pb(cx), my.pb(cy);
}
} else {
int cx = (x[a] + x[b]) / 2;
int cy = y[a] + ((x[a] + y[a]) % 4 ? -1 : 1);
if (!s.count({cx, cy})) {
s.emplace(cx, cy);
merge(a, b);
u.pb(a), v.pb(b);
mx.pb(cx), my.pb(cy);
}
}
}
if (u.size() != n - 1) return 0;
build(u, v, mx, my);
return 1;
}
Compilation message
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:48:9: error: 'debug' was not declared in this scope
48 | debug(a, b, x[a], y[a], x[b], y[b]);
| ^~~~~
parks.cpp:69:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
69 | if (u.size() != n - 1) return 0;
| ~~~~~~~~~^~~~~~~~