#B3760. Dice Reconstruction
Dice Reconstruction
Dice Reconstruction
You are given a special dice with six faces. Each face bears a number between and (inclusive), but numbers on different faces may repeat. You took several photographs of the dice from different angles using a camera. However, due to the camera’s viewpoint, each photograph captures only three faces of the dice. Note that since the dice can be arbitrarily rotated, the three faces in any photograph always share a common vertex.
Assume the dice faces are fixed in the following order: top, bottom, front, back, left, and right. With this labeling, the eight vertices of the dice correspond to the following face index triples (using 0‐based indices for faces as shown below):
• Vertex 1: (top, front, left) → (0, 2, 4) • Vertex 2: (top, front, right) → (0, 2, 5) • Vertex 3: (top, back, left) → (0, 3, 4) • Vertex 4: (top, back, right) → (0, 3, 5) • Vertex 5: (bottom, front, left) → (1, 2, 4) • Vertex 6: (bottom, front, right) → (1, 2, 5) • Vertex 7: (bottom, back, left) → (1, 3, 4) • Vertex 8: (bottom, back, right) → (1, 3, 5)
Each photograph provides three integers (possibly with duplicates) which represent the numbers observed on some vertex’s three faces (order does not matter). Your task is to find a dice configuration (i.e. assign a number to each face in the order top, bottom, front, back, left, right) such that for every photograph there exists at least one vertex whose three face numbers (when sorted) exactly match the numbers from that photograph (when sorted).
If there are multiple valid configurations, output the lexicographically smallest one (i.e. treat the configuration as a 6-tuple and choose the smallest in dictionary order). If no valid configuration exists, output "Impossible".
inputFormat
The first line contains an integer (), the number of photographs. Each of the next lines contains three integers, representing the numbers observed in that photograph.
outputFormat
If a valid configuration exists, output six integers separated by spaces denoting the numbers on the dice faces in the order: top, bottom, front, back, left, right. Otherwise, output "Impossible".
sample
8
1 2 3
1 2 6
1 3 5
1 5 6
4 2 3
4 2 6
4 3 5
4 5 6
1 4 2 5 3 6