Balls and Needles
Time limit2sMemory limit512 MB
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 is a set of two different triples, .
Ana dislikes closed chains. A true closed chain is a sequence of distinct needles for some such that:
- , , ..., , and .
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 , write for the shadow of on the floor. For Ana, who is an artist, a floor closed chain is also a sequence of distinct needles for some such that:
- for every , so the needle shadows are all distinct;
- , , ..., , and .
Consider the sculpture whose four knitting needles are , , , . This structure is not free of closed chains: there is no true closed chain, but the sequence 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 , the number of knitting needles in the sculpture. Each of the next lines contains six integers , , , , , , which mean that 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
- , the number of knitting needles
- , each coordinate of a triple