#P9163. Slip Knot or Dead Knot?

    ID: 22320 Type: Default 1000ms 256MiB

Slip Knot or Dead Knot?

Slip Knot or Dead Knot?

A knot can be represented by its crossing points and connections. In our model, each crossing point has four exits. We denote an exit by a tuple $$ (u,d) $$, where:

  • For a crossing point, \( u \ge 0 \) is its index and \( d\in \{0,1,2,3\} \) represents the direction.
  • It is prescribed that exits with \( d=0,1 \) are the upper exits and with \( d=2,3 \) are the lower exits.

Moreover, each crossing point inherently connects its two upper exits and its two lower exits. That is, for any crossing point \( u \), there is an internal connection between \( (u,0) \) and \( (u,1) \), and between \( (u,2) \) and \( (u,3) \).

The knot also has two endpoints that connect to the outside, which are denoted by \( (-1,0) \) and \( (-2,0) \). In addition to the internal connections at the crossings, the knot is given by a set of external connections linking two exits. Each such connection is represented by two tuples, for example, (u₁, d₁) (u₂, d₂).

Your task is: when the two endpoints are pinched and pulled, decide whether the knot is a slip knot (i.e. it can be undone by pulling) or a dead knot (it remains tied).

If the knot is a slip knot print Yes, otherwise print No.

Note: Mathematically, you should decide by checking if there exists a continuous path (through both the external connections and the inherent internal connections at crossings) connecting the two endpoints \( (-1,0) \) and \( (-2,0) \). If such a path exists, the knot is a slip knot.

inputFormat

The first line contains an integer \( m \), the number of external connections in the knot.

Each of the next \( m \) lines contains four space-separated integers: u₁ d₁ u₂ d₂, indicating an external connection between exit \( (u₁, d₁) \) and exit \( (u₂, d₂) \). Note that endpoints are represented as \( (-1,0) \) and \( (-2,0) \), and for a crossing point, \( u \ge 0 \) and \( d\in \{0,1,2,3\} \).

outputFormat

Output a single line: Yes if the knot is a slip knot, or No if it is a dead knot.

sample

1
-1 0 -2 0
Yes