#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> l;
map<pt, bool> m;
set<int> ax;
void dfs(pt x) {
m[x] = true;
for (int axis : ax) {
pt next = x;
next[axis]++;
if (l.count(next) && !m[next]) {
dfs(next);
}
next[axis] -= 2;
if (l.count(next) && !m[next]) {
dfs(next);
}
}
}
void validate_layer(int i) {
ax = {0, 1, 2};
ax.erase(i);
m.clear();
dfs(*l.begin());
for (pt p : l) {
if (!m[p]) {
cout << "NO\n";
exit(0);
}
}
sp.clear();
for (pt p : l) {
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;
}
int c = a;
a = b;
b = c;
}
}
void dfs3d(pt x) {
m[x] = true;
for (int axis : ax) {
pt next = x;
next[axis]++;
if (l.count(next) && !m[next])
dfs3d(next);
next[axis] -= 2;
if (l.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 >> x;
points[n][0] = x;
}
for (ll n = 0; n < N; n++) {
input >> x;
points[n][1] = x;
}
for (ll n = 0; n < N; n++){
input >> x;
points[n][2] = x;
}
for (pt p : points)
l.insert(p);
ax = {0, 1, 2};
dfs3d(points[0]);
for (pt p : points) {
if (!m[p]) {
cout << "NO\n";
exit(0);
}
}
l.clear();
for (int i = 0; i < 3; i++) {
copy_n(points.begin(), N, ps.begin());
sort(ps.begin(), ps.end(), [&](pt a, pt b) {
return a[i] < b[i];
});
ll layer = ps[0][i];
l.clear();
for (pt p : ps) {
if (p[i] != layer) {
validate_layer(i);
layer = p[i];
l.clear();
}
l.insert(p);
}
validate_layer(i);
}
cout << "YES\n";
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1952 KiB | ||||
2 | Accepted | 3ms | 2152 KiB | ||||
3 | Accepted | 3ms | 2372 KiB | ||||
subtask2 | 18/18 | ||||||
4 | Accepted | 3ms | 2460 KiB | ||||
5 | Accepted | 3ms | 2716 KiB | ||||
6 | Accepted | 3ms | 2832 KiB | ||||
7 | Accepted | 3ms | 3040 KiB | ||||
8 | Accepted | 3ms | 3128 KiB | ||||
9 | Accepted | 3ms | 3216 KiB | ||||
10 | Accepted | 3ms | 3220 KiB | ||||
11 | Accepted | 3ms | 3288 KiB | ||||
12 | Accepted | 3ms | 3216 KiB | ||||
13 | Accepted | 3ms | 3480 KiB | ||||
subtask3 | 19/19 | ||||||
14 | Accepted | 7ms | 4780 KiB | ||||
15 | Accepted | 3ms | 3456 KiB | ||||
16 | Accepted | 18ms | 6312 KiB | ||||
17 | Accepted | 35ms | 8084 KiB | ||||
18 | Accepted | 61ms | 8060 KiB | ||||
19 | Accepted | 61ms | 7936 KiB | ||||
20 | Accepted | 3ms | 3664 KiB | ||||
21 | Accepted | 16ms | 5900 KiB | ||||
22 | Accepted | 27ms | 8060 KiB | ||||
23 | Accepted | 28ms | 8076 KiB | ||||
24 | Accepted | 46ms | 7940 KiB | ||||
25 | Accepted | 26ms | 7944 KiB | ||||
26 | Accepted | 3ms | 3752 KiB | ||||
subtask4 | 24/24 | ||||||
27 | Accepted | 79ms | 25692 KiB | ||||
28 | Accepted | 10ms | 5380 KiB | ||||
29 | Accepted | 902ms | 69172 KiB | ||||
30 | Accepted | 945ms | 73748 KiB | ||||
31 | Accepted | 934ms | 69092 KiB | ||||
32 | Accepted | 930ms | 69264 KiB | ||||
33 | Accepted | 7ms | 4788 KiB | ||||
34 | Accepted | 507ms | 58452 KiB | ||||
35 | Accepted | 925ms | 65600 KiB | ||||
36 | Accepted | 620ms | 63544 KiB | ||||
37 | Accepted | 938ms | 63708 KiB | ||||
38 | Accepted | 356ms | 66536 KiB | ||||
39 | Accepted | 6ms | 5268 KiB | ||||
subtask5 | 22/22 | ||||||
40 | Accepted | 83ms | 26364 KiB | ||||
41 | Accepted | 4ms | 5108 KiB | ||||
42 | Accepted | 111ms | 22048 KiB | ||||
43 | Accepted | 486ms | 67532 KiB | ||||
44 | Accepted | 1.039s | 66496 KiB | ||||
45 | Accepted | 1.072s | 67504 KiB | ||||
46 | Accepted | 3ms | 4904 KiB | ||||
47 | Accepted | 3ms | 4908 KiB | ||||
48 | Accepted | 75ms | 16312 KiB | ||||
49 | Accepted | 501ms | 56020 KiB | ||||
50 | Accepted | 485ms | 65632 KiB | ||||
51 | Accepted | 758ms | 67460 KiB | ||||
52 | Accepted | 409ms | 68252 KiB | ||||
53 | Accepted | 3ms | 5212 KiB | ||||
subtask6 | 17/17 | ||||||
54 | Accepted | 85ms | 26900 KiB | ||||
55 | Accepted | 550ms | 70380 KiB | ||||
56 | Accepted | 451ms | 62872 KiB | ||||
57 | Accepted | 550ms | 63912 KiB | ||||
58 | Accepted | 723ms | 67000 KiB | ||||
59 | Accepted | 1.072s | 68296 KiB | ||||
60 | Accepted | 344ms | 71048 KiB | ||||
61 | Accepted | 456ms | 59492 KiB | ||||
62 | Accepted | 523ms | 68220 KiB | ||||
63 | Accepted | 713ms | 68580 KiB | ||||
64 | Accepted | 1.072s | 67344 KiB | ||||
65 | Accepted | 423ms | 67820 KiB | ||||
66 | Accepted | 541ms | 80404 KiB |