#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
ifstream in_file("minta/be1.txt");
#define input in_file
#define INTHENAMEOFGOD
#else
#define input cin
#define INTHENAMEOFGOD \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#endif
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<ll, ll> pii;
typedef array<ll, 3> pt;
ll N, x;
vector<pt> ps, points, sp;
set<pt> layer;
map<pt, bool> m;
set<int> ax;
void dfs(pt x) {
m[x] = true;
for (int axis : ax) {
pt next = x;
next[axis]++;
if (layer.count(next) && !m[next]) {
dfs(next);
}
next[axis] -= 2;
if (layer.count(next) && !m[next]) {
dfs(next);
}
}
}
void validate_layer(int i) {
ax = {0, 1, 2};
ax.erase(i);
m.clear();
dfs(*layer.begin());
for (pt p : layer) {
if (!m[p]) {
cout << "NO\n";
exit(0);
}
}
sp.clear();
for (pt p : layer) {
sp.push_back(p);
}
int a = *ax.begin();
int b = *++ax.begin();
for (int i = 0; i < 2; i++) {
sort(sp.begin(), sp.end(), [&](pt l, pt r) {
if (l[a] == r[a])
return l[b] < r[b];
return l[a] < r[a];
});
ll row = -1;
pt last;
for (pt p : sp) {
if (p[a] != row)
row = p[a];
else if (p[b] != last[b]+1) {
cout << "NO\n";
exit(0);
}
last = p;
}
swap(a, b);
}
}
void dfs3d(pt x) {
m[x] = true;
for (int axis : ax) {
pt next = x;
next[axis]++;
if (layer.count(next) && !m[next])
dfs3d(next);
next[axis] -= 2;
if (layer.count(next) && !m[next])
dfs3d(next);
}
}
int main() {
INTHENAMEOFGOD
input >> N;
points.resize(N);
ps.resize(N);
for (ll n = 0; n < N; n++)
input >> points[n][0];
for (ll n = 0; n < N; n++)
input >> points[n][1];
for (ll n = 0; n < N; n++)
input >> points[n][2];
for (pt p : points)
layer.insert(p);
ax = {0, 1, 2};
dfs3d(points[0]);
for (pt p : points) {
if (!m[p]) {
cout << "NO\n";
exit(0);
}
}
layer.clear();
copy_n(points.begin(), N, ps.begin());
for (int axis = 0; axis < 3; axis++) {
sort(ps.begin(), ps.end(), [&](pt a, pt b) {
return a[axis] < b[axis];
});
ll layer_ind = ps[0][axis];
layer.clear();
for (pt p : ps) {
if (p[axis] != layer_ind) {
validate_layer(axis);
layer_ind = p[axis];
layer.clear();
}
layer.insert(p);
}
validate_layer(axis);
}
cout << "YES\n";
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1976 KiB | ||||
2 | Accepted | 3ms | 2204 KiB | ||||
3 | Accepted | 3ms | 2276 KiB | ||||
subtask2 | 18/18 | ||||||
4 | Accepted | 3ms | 2652 KiB | ||||
5 | Accepted | 3ms | 2748 KiB | ||||
6 | Accepted | 3ms | 3112 KiB | ||||
7 | Accepted | 3ms | 3188 KiB | ||||
8 | Accepted | 3ms | 3440 KiB | ||||
9 | Accepted | 3ms | 3512 KiB | ||||
10 | Accepted | 3ms | 3556 KiB | ||||
11 | Accepted | 4ms | 3620 KiB | ||||
12 | Accepted | 3ms | 3684 KiB | ||||
13 | Accepted | 3ms | 3900 KiB | ||||
subtask3 | 19/19 | ||||||
14 | Accepted | 7ms | 5204 KiB | ||||
15 | Accepted | 3ms | 4008 KiB | ||||
16 | Accepted | 18ms | 6556 KiB | ||||
17 | Accepted | 34ms | 8116 KiB | ||||
18 | Accepted | 61ms | 8244 KiB | ||||
19 | Accepted | 59ms | 8120 KiB | ||||
20 | Accepted | 3ms | 4132 KiB | ||||
21 | Accepted | 16ms | 6552 KiB | ||||
22 | Accepted | 26ms | 8760 KiB | ||||
23 | Accepted | 28ms | 9060 KiB | ||||
24 | Accepted | 45ms | 8952 KiB | ||||
25 | Accepted | 25ms | 8912 KiB | ||||
26 | Accepted | 3ms | 4532 KiB | ||||
subtask4 | 24/24 | ||||||
27 | Accepted | 79ms | 26220 KiB | ||||
28 | Accepted | 10ms | 6032 KiB | ||||
29 | Accepted | 879ms | 69740 KiB | ||||
30 | Accepted | 859ms | 74324 KiB | ||||
31 | Accepted | 873ms | 69656 KiB | ||||
32 | Accepted | 860ms | 69732 KiB | ||||
33 | Accepted | 7ms | 5392 KiB | ||||
34 | Accepted | 476ms | 59028 KiB | ||||
35 | Accepted | 856ms | 65900 KiB | ||||
36 | Accepted | 619ms | 63888 KiB | ||||
37 | Accepted | 899ms | 64184 KiB | ||||
38 | Accepted | 352ms | 66652 KiB | ||||
39 | Accepted | 6ms | 5276 KiB | ||||
subtask5 | 22/22 | ||||||
40 | Accepted | 78ms | 26220 KiB | ||||
41 | Accepted | 3ms | 4488 KiB | ||||
42 | Accepted | 109ms | 21616 KiB | ||||
43 | Accepted | 510ms | 67056 KiB | ||||
44 | Accepted | 1.036s | 66204 KiB | ||||
45 | Accepted | 1.036s | 67112 KiB | ||||
46 | Accepted | 3ms | 4492 KiB | ||||
47 | Accepted | 3ms | 4492 KiB | ||||
48 | Accepted | 74ms | 15824 KiB | ||||
49 | Accepted | 477ms | 55412 KiB | ||||
50 | Accepted | 490ms | 65048 KiB | ||||
51 | Accepted | 786ms | 66964 KiB | ||||
52 | Accepted | 425ms | 67808 KiB | ||||
53 | Accepted | 3ms | 4604 KiB | ||||
subtask6 | 17/17 | ||||||
54 | Accepted | 83ms | 26256 KiB | ||||
55 | Accepted | 531ms | 69924 KiB | ||||
56 | Accepted | 446ms | 62412 KiB | ||||
57 | Accepted | 529ms | 63480 KiB | ||||
58 | Accepted | 680ms | 66420 KiB | ||||
59 | Accepted | 1.057s | 67584 KiB | ||||
60 | Accepted | 345ms | 70316 KiB | ||||
61 | Accepted | 460ms | 58616 KiB | ||||
62 | Accepted | 493ms | 67448 KiB | ||||
63 | Accepted | 695ms | 67836 KiB | ||||
64 | Accepted | 1.047s | 66676 KiB | ||||
65 | Accepted | 411ms | 67068 KiB | ||||
66 | Accepted | 490ms | 79624 KiB |