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.
Medium4GraphUnion-findHash mapGeometryNo attempts yetTime limit2sMemory limit512 MBJoana 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 N is a set of two different triples, N={(x,y,z),(x′,y′,z′)}.
Ana dislikes closed chains. A true closed chain is a sequence of k distinct needles N1,N2,...,Nk for some k≥3 such that:
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′)}, write N↓={(x,y),(x′,y′)} for the shadow of N on the floor. For Ana, who is an artist, a floor closed chain is also a sequence of k distinct needles N1,N2,...,Nk for some k≥3 such that:
Consider the sculpture whose four knitting needles are A={(12,12,8),(10,5,11)}, B={(12,12,8),(4,14,21)}, C={(12,12,8),(12,20,8)}, 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,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.
The first line contains one integer K, the number of knitting needles in the sculpture. Each of the next K lines contains six integers x1, y1, z1, x2, y2, z2, which mean that {(x1,y1,z1),(x2,y2,z2)} 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.
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.