<b>TLE '16 Contest 4 P3 - Cubes</b> Jason recently bought a frame from Ikea. After…
- User
TLE '16 Contest 4 P3 - Cubes
Jason recently bought a frame from Ikea. After assembling this cubic frame, Jason will place a large piece of glass on top of the frame, forming a table for his friends to eat at during an upcoming Christmas party.
According to the Ikea instructions, there are 8 distinct corners of the frame (vertices), labelled from 1 to 8. Jason is also given (N) distinct beams. The (i)th beam can only connect corners (u_i) and (v_i). Jason is allowed to choose any beam to include in the frame and he can place the corners in any position in 3-D space. Can Jason build the cubic frame?
Input Specification
The first line contains the integer (N) ((0 \leq N \leq 28)).
(N) lines of input follow. The (i)th line contains the integers (u_i) and (v_i) ((u_i < v_i)). No pair ((u_i, v_i)) appears twice in the input.
Output Specification
Output Ja if it is possible for Jason to build a cubic frame. Otherwise, output Nej.
Sample Input 1 (\bullet) 12 (\bullet) 1 2 (\bullet) 2 3 (\bullet) 3 4 (\bullet) 1 4 (\bullet) 5 6 (\bullet) 6 7 (\bullet) 7 8 (\bullet) 5 8 (\bullet) 1 5 (\bullet) 2 6 (\bullet) 3 7 (\bullet) 4 8
Sample Output 1 (\bullet) Ja
Sample Input 2 (\bullet) 6 (\bullet) 1 2 (\bullet) 1 3 (\bullet) 1 4 (\bullet) 2 3 (\bullet) 2 4 (\bullet) 3 4
Sample Output 2 (\bullet) Nej
To solve this problem, it is necessary to choose all possible locations of the 8 corners. This can be done with a permutation.
To check if a position is valid, there should be 12 beams in the proper locations. Any remaining beams do not matter and can be thrown away.
Time complexity: (O(V! \ast E)) where (V = 8) is the number of corners and (E = 12) is the number of beams in the cubic frame.
One common mistake is just counting the number of beams that connect to a corner. For 2 tetrahedra, there are 8 corners and 12 beams, and each corner is connected to 3 beams. It is not possible to create a cube from 2 tetrahedra. solve in c++
- Assistant