#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const ll inf = 1e9;
const int md1 = 1e9+7;
const int md2 = 998244353;
#define sz(v) ((int)v.size())
#define pb push_back
#define pry cout << "YES\n"
#define prn cout << "NO\n"
#define endl '\n'
#define fst first
#define scn second
/* #define ONPC */
#define addedg bench.insert(tpls); uni(ind, tind); u.pb(ind); v.pb(tind); ansa.pb(tind%X); ansb.pb(tind/X);
using vi = vector<int>;
const ll X= 2e5+10;
int p[X];
set<ll> bench;
set<ll> fount;
map<ll, int> fnt;
int ucount;
int getp(int x) { return p[x] = (p[x] == x) ? x : getp(p[x]); }
ll cord(ll x, ll y) { return y * X + x; }
void build (vi u, vi v, vi a, vi b);
void
uni(int a, int b)
{
a = getp(a);
b = getp(b);
if (a == b) return;
++ucount;
p[a] = b;
return;
}
int
construct_roads(vi x, vi y)
{
int n = sz(x);
vector<ll> q;
for (int i = 0; i < n; ++i) {
p[i] = i;
fount.insert(cord(x[i],y[i]));
fnt[(cord(x[i],y[i]))] = i;
q.pb(cord(x[i],y[i]));
}
sort(q.begin(), q.end());
int a,b, ind, tind;
int tpls;
vi u, v, ansa, ansb;
for (int i = 0; i < n; ++i) {
a = q[i] % X;
b = q[i] / X;
ind = fnt[q[i]];
if (fount.count(cord(a+2,b))) {
tind = fnt[cord(a+2,b)];
if (getp(tind) != getp(ind)) {
if ((a+b) & 2) tpls = cord(a+1,b-1);
else tpls = cord(a+1,b+1);
if (bench.count(tpls) == 0) {
addedg;
}
}
}
if (fount.count(cord(a,b+2))) {
tind = fnt[cord(a,b+2)];
if (getp(tind) != getp(ind)) {
if ((a+b) & 2) tpls = cord(a+1,b+1);
else tpls = cord(a-1,b+1);
if (bench.count(tpls) == 0) {
addedg;
}
}
}
}
if (ucount != n-1) return 0;
build(u, v, ansa, ansb);
return 1;
}
#ifdef ONPC
void
build(vi u, vi v, vi a, vi b)
{
}
void
solve()
{
int n;
cin >> n;
vi x(n), y(n);
for (int i = 0; i < n; ++i) {
cin >> x[i] >> y[i];
}
cout << construct_roads(x, y) << endl;
}
int32_t
main(int argc, char **argv)
{
if (argc >= 2) {
freopen(argv[1], "r", stdin);
} else
ios_base::sync_with_stdio(0);cin.tie(0);
int t = 1;
/* cin >> t; */
while(t--)
solve();
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
b[0] = 0 is not an odd integer |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
b[0] = 0 is not an odd integer |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
b[0] = 0 is not an odd integer |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
b[0] = 0 is not an odd integer |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
b[0] = 0 is not an odd integer |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
b[0] = 0 is not an odd integer |
3 |
Halted |
0 ms |
0 KB |
- |