#P7014. Link Endurance Verification
Link Endurance Verification
Link Endurance Verification
Chain & Co. produces high‐quality, infinitely strong chain links in the form of three-dimensional, axis‐aligned square frames. In each frame the four segments form a perfect square with no thickness. In the testing setup the frames are positioned so that no two touch. Nevertheless, due to interlocking they may be inseparable: two links are said to be inseparable if they cannot be moved apart without breaking one of them.
The links come in three different orientations: the square may lie in the XY, YZ, or ZX plane. In our input, each link is given as follows:
- For a link in the XY plane:
XY z x y s
. The link lies in the plane z = constant and covers the open intervals (x, x+s) and (y, y+s). - For a link in the YZ plane:
YZ x y z s
. The link lies in the plane x = constant and covers the open intervals (y, y+s) and (z, z+s). - For a link in the ZX plane:
ZX y z x s
. The link lies in the plane y = constant and covers the open intervals (z, z+s) and (x, x+s).
Two links in perpendicular planes may be inseparably linked. Their linking is determined as follows:
- XY and YZ: Let LXY be a link in the XY plane with constant z and intervals (x, x+s) and (y, y+s), and LYZ be a link in the YZ plane with constant x and intervals (y, y+s) and (z, z+s). They are linked if and only if:
- LXY's constant z lies strictly inside LYZ's z-interval.
- LYZ's constant x lies strictly inside LXY's x-interval.
- Their y-intervals (LXY's second coordinate and LYZ's first coordinate) overlap (i.e. the open intervals have a nonempty intersection).
- XY and ZX: Let LXY be from the XY plane and LZX from the ZX plane. Here, LXY has constant z and intervals (x, x+s) and (y, y+s) while LZX has constant y and intervals (z, z+s) and (x, x+s). They are linked if and only if:
- LZX's constant y lies strictly inside LXY's y-interval.
- LXY's constant z lies strictly inside LZX's z-interval.
- Their x-intervals (LXY's first coordinate and LZX's second coordinate) overlap.
- YZ and ZX: Let LYZ be from the YZ plane (constant x, intervals (y, y+s) and (z, z+s)) and LZX from the ZX plane (constant y, intervals (z, z+s) and (x, x+s)). They are linked if and only if:
- LYZ's constant x lies strictly inside LZX's x-interval.
- LZX's constant y lies strictly inside LYZ's y-interval.
- Their z-intervals (LYZ's second coordinate and LZX's first coordinate) overlap.
Links that lie in the same plane (or in parallel planes) are never linked. Note that the links do not even touch.
Your task is to decide whether a given set of links (all pairwise disjoint) is in a proper testing position; that is, can the links be divided into two nonempty groups A and B such that every link in A is inseparably linked with every link in B?
inputFormat
The first line contains an integer n (n ≥ 2), the number of links. Each of the next n lines describes a link with the format:
plane c u v s
Here, plane
is one of XY
, YZ
, or ZX
. Depending on the plane:
- If plane is XY: the link lies in the plane z = c, and covers the open intervals (u, u+s) in x and (v, v+s) in y.
- If plane is YZ: the link lies in the plane x = c, and covers (u, u+s) in y and (v, v+s) in z.
- If plane is ZX: the link lies in the plane y = c, and covers (u, u+s) in z and (v, v+s) in x.
All numbers are integers and are chosen so that links do not touch.
outputFormat
Output a single line containing Yes
if the links can be partitioned into two nonempty groups A and B so that every link in A is linked with every link in B, and No
otherwise.
sample
2
XY 5 1 1 10
YZ 6 2 0 10
Yes