Under construction

Still being built. Things may change

Balls and Needles

Time limit2sMemory limit512 MB

Summary
Given K segments in 3D defined by endpoint triples, decide whether they form a closed cycle in space and whether their projections onto the xy-plane form a closed cycle.
Level

Medium4 of 10

Topics
Graph, Union-find, Hash map, Geometry
Solved
No attempts yet

Problem

Joana Vasconcelos is a Portuguese artist who makes works out of everyday objects such as electric irons and plastic cutlery. Ana takes her inspiration from that work and wants to build ceiling sculptures out of straight knitting needles and balls of wool. For safety, one ball sits at each end of every needle. The needles differ in colour, length and thickness, so needles are allowed to cross each other.

A sculpture is exhibited in a corner of a room. The corner gives a 3D Cartesian coordinate system, and the ceiling holds many lamps. A design records the coordinates of the centres of the balls of wool that the needles are stuck into. That is, each needle NN is a set of two different triples, N={(x,y,z),(x′,y′,z′)}N = \{(x,y,z),(x',y',z')\}.

Ana dislikes closed chains. A true closed chain is a sequence of kk distinct needles N1,N2,...,NkN_1, N_2, ..., N_k for some k≥3k \ge 3 such that:

  • N1={(x1,y1,z1),(x2,y2,z2)}N_1 = \{(x_1,y_1,z_1),(x_2,y_2,z_2)\}, N2={(x2,y2,z2),(x3,y3,z3)}N_2 = \{(x_2,y_2,z_2),(x_3,y_3,z_3)\}, ..., Nk={(xk,yk,zk),(xk+1,yk+1,zk+1)}N_k = \{(x_k,y_k,z_k),(x_{k+1},y_{k+1},z_{k+1})\}, and (xk+1,yk+1,zk+1)=(x1,y1,z1)(x_{k+1},y_{k+1},z_{k+1}) = (x_1,y_1,z_1).

Her dislike of closed chains goes further: the shadow of the sculpture on the floor also has to be free of floor closed chains. For a needle N={(x,y,z),(x′,y′,z′)}N = \{(x,y,z),(x',y',z')\}, write N↓={(x,y),(x′,y′)}N^{\downarrow} = \{(x,y),(x',y')\} for the shadow of NN on the floor. For Ana, who is an artist, a floor closed chain is also a sequence of kk distinct needles N1,N2,...,NkN_1, N_2, ..., N_k for some k≥3k \ge 3 such that:

  • Ni↓≠Nj↓N_i^{\downarrow} \ne N_j^{\downarrow} for every 1≤i<j≤k1 \le i < j \le k, so the kk needle shadows are all distinct;
  • N1↓={(x1,y1),(x2,y2)}N_1^{\downarrow} = \{(x_1,y_1),(x_2,y_2)\}, N2↓={(x2,y2),(x3,y3)}N_2^{\downarrow} = \{(x_2,y_2),(x_3,y_3)\}, ..., Nk↓={(xk,yk),(xk+1,yk+1)}N_k^{\downarrow} = \{(x_k,y_k),(x_{k+1},y_{k+1})\}, and (xk+1,yk+1)=(x1,y1)(x_{k+1},y_{k+1}) = (x_1,y_1).

Consider the sculpture whose four knitting needles are A={(12,12,8),(10,5,11)}A = \{(12,12,8),(10,5,11)\}, B={(12,12,8),(4,14,21)}B = \{(12,12,8),(4,14,21)\}, C={(12,12,8),(12,20,8)}C = \{(12,12,8),(12,20,8)\}, D={(4,14,21),(10,5,21)}D = \{(4,14,21),(10,5,21)\}. This structure is not free of closed chains: there is no true closed chain, but the sequence A,B,DA, B, D is a floor closed chain.

Given the knitting needles of a sculpture, decide whether the sculpture contains a true closed chain and whether it contains a floor closed chain.

Input

The first line contains one integer KK, the number of knitting needles in the sculpture. Each of the next KK lines contains six integers x1x_1, y1y_1, z1z_1, x2x_2, y2y_2, z2z_2, which mean that {(x1,y1,z1),(x2,y2,z2)}\{(x_1,y_1,z_1),(x_2,y_2,z_2)\} is the set of triples of one needle. The two triples of a needle are different, and any two distinct needles are given as different sets of triples.

Output

Print two lines, each with one string.

On the first line print True closed chains if the sculpture contains some true closed chain, and No true closed chains otherwise.

On the second line print Floor closed chains if the sculpture contains some floor closed chain, and No floor closed chains otherwise.

Constraints

  • 1≤K≤500001 \le K \le 50000, the number of knitting needles
  • 1≤xi,yi,zi≤10001 \le x_i, y_i, z_i \le 1000, each coordinate of a triple

Examples4

  1. Example 1

    Input
    4
    12 12 8 10 5 11
    12 12 8 4 14 21
    12 12 8 12 20 8
    4 14 21 10 5 21
    
    Expected output
    No true closed chains
    Floor closed chains
    
  2. Example 2

    Input
    4
    1 1 1 2 2 2
    2 2 2 1 5 5
    9 4 4 9 4 2
    9 4 4 9 9 4
    
    Expected output
    No true closed chains
    No floor closed chains
    
  3. Example 3

    Input
    3
    50 50 50 100 100 100
    100 100 100 50 50 90
    50 50 90 50 50 50
    
    Expected output
    True closed chains
    No floor closed chains
    
  4. Example 4

    Input
    3
    1 1 5 1 3 7
    1 3 7 4 4 5
    4 4 5 1 1 5
    
    Expected output
    True closed chains
    Floor closed chains