Packing Unit 4D Cubes

Description

We usually think that there are three geometric dimensions; the fourth dimension is usually time. However, the Association for Customizing Machines (ACM) has to deal with four geometrical dimensions for their strange customer EE3 who needs to pack four dimensional products into perpendicular parallelepipeds before shipping them to the newly emerged market niche just on the outskirts of the Milky Way.
Each of EE3 products consists of a number of unit 4D cubes that are glued together at their faces. A face of a 4D cube is a 3D cube and each 4D cube has 8 such faces. The picture on the left shows a 4D cube projected into a plane with the four principal, orthogonal axes shown. It takes a bit of effort to stretch our imagination and see the faces of a 4D cube in such a projection. The pictures below try to illustrate how the two faces along each of the four axes are situated in 4D. Again, using just the planar projection it is not so easy to illustrate and takes some effort to see. But we have done a good job, didn't we?

Each EE3 product to be packed consists of a number of unit 4D cubes that are glued together along their faces which are 3D cubes. Your job is simple: find the minimal volume measured in the number of unit 4D cubes of a perpendicular parallelepiped (a 4D box) into which the product can be packed before shipping.
Input

The first line of the input file contains a single integer t (1 ≤ t ≤ 10), the number of test cases, followed by input data for each test case describing one EE3 product. The first line of each test case is an integer n (1 ≤ n ≤ 100) which is the number of unit 4D cubes used in the product. Next, there are n lines, each describing one unit cube and contains 9 nonnegative integer numbers.
The first number, a positive integer, is the unique identifier of a cube and the remaining 8 numbers give the identities of neighbors of the cube listed in the following order:
?the first two numbers are identifiers of the cubes glued to the opposing sides of the given cube along the x1 axis as seen looking in the direction of the x1 axis;
?the next two numbers as above but for the x2 axis;
?the next two numbers as above but for the x3 axis;
?the next two numbers as above but for the x4 axis;
If a cube does not have a neighbor glued to one of its faces we use 0 instead of a cube identifier.
The problem is that the employees of ACM may produce inconsistent descriptions of EE3 products. There are two sources of such inconsistencies:
?A consistent description must be symmetric, i.e. if cube x is glued to cube y at some face then cube y must be glued to cube x at the corresponding face along the same axis. The following description is inconsistent:
3 0 0 1 0 0 0 0 0
1 0 0 3 0 0 0 0 0
?Any description must describe a single solid, i.e. there must be only one component in the product. Thus the following is inconsistent:
1 2 0 0 0 0 0 0 0
2 0 1 0 0 0 0 0 0
3 0 0 4 0 0 0 0 0
4 0 0 0 3 0 0 0 0
Output

There should be one output line per test case containing either the number of unit 4D cubes in the smallest 4D perpendicular parallelepiped oriented along the axes into which the product can be packed if the description is consistent, or the word Inconsistent, otherwise.
Sample Input

1
9
1 2 3 4 5 6 7 8 9
2 0 1 0 0 0 0 0 0
3 1 0 0 0 0 0 0 0
4 0 0 0 1 0 0 0 0
5 0 0 1 0 0 0 0 0
6 0 0 0 0 0 1 0 0
7 0 0 0 0 1 0 0 0
8 0 0 0 0 0 0 0 1
9 0 0 0 0 0 0 1 0
Sample Output

81

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问

相似问题

2
这是一个有关魔方的问题,请问怎么计算旋转的步数
0
数据结构的广度优先的搜索的算法,多个路径递归怎么用 C 程序实现了
0
正六面体的转动求体积交集问题,如何利用C语言的编程技术实现的
0
一个图的搜索的数据结构组织的问题,用C程序设计的语言实现的方式
0
计算魔方的最少旋转的次数的问题,怎么利用C语言的程序的编写的过程来实现的?
0
用字符构成的立体方块图的算法,怎么采用C程序的代码语言的编写的过程实现?
0
由字符串构成的一个立方体的图案的生成,怎么利用C程序语言代码编写的方式来进行的?
0
超立方体的的构造命题的算法,怎么采用C程序的语言代码编写的技术去实现?
0
正立方体的匹配问题的计算,怎么采用C程序的语言的代码编写的技术实现的?
0
计算批量的容量矩阵的问题,怎么使用C语言的程序的设计的形式的思想去解决?
2
计算有多少种不同的魔方的一个计算,怎么使用C语言的程序的编写的过程的设计来实现的呢?
0
使用ascii画出正方体的问题,怎么使用C语言的程序的设计的形式来回答的,代码的实现
0
立方体的整齐的排列的算法,怎么采用C语言的程序的设计的格式来实现的
0
立方体的一个遍历的问题求解,怎么采用C语言的程序的设计的技术的编写的程序怎么做
0
算法Hypertheseus问题的解答的方法
0
Who's Aunt Zhang
0
用C语言解决魔方的问题的解决思路
0
程序设计, Who's Aunt Zhang
0
方块计算, Area of Polycubes
0
Pocket Cube模仿的问题,怎么实现