BULK - The Bulk!

no tags 

ACM uses a new special technology of building its transceiver stations. This technology is called Modular Cuboid Architecture (MCA) and is covered by a patent of Lego company. All parts of the transceiver are shipped in unit blocks that have the form of cubes of exactly the same size. The cubes can be then connected to each other. The MCA is modular architecture, that means we can select preferred transceiver configuration and buy only those components we need .

The cubes must be always connected "face-to-face", i.e. the whole side of one cube is connected to the whole side of another cube. One cube can be thus connected to at most six other units. The resulting equipment, consisting of unit cubes is called The Bulk in the communication technology slang.

Sometimes, an old and unneeded bulk is condemned, put into a storage place, and replaced with a new one. It was recently found that ACM has many of such old bulks that just occupy space and are no longer needed. The director has decided that all such bulks must be disassembled to single pieces to save some space. Unfortunately, there is no documentation for the old bulks and nobody knows the exact number of pieces that form them. You are to write a computer program that takes the bulk description and computes the number of unit cubes.

Each bulk is described by its faces (sides). A special X-ray based machine was constructed that is able to localise all faces of the bulk in the space, even the inner faces, because the bulk can be partially hollow (it can contain empty spaces inside). But any bulk must be connected (i.e. it cannot drop into two pieces) and composed of whole unit cubes.

Input

There is a single positive integer T on the first line of input (equal to about 1000). It stands for the number of bulks to follow. Each bulk description begins with a line containing single positive integer F, 6 <= F <= 250, stating the number of faces. Then there are F lines, each containing one face description. All faces of the bulk are always listed, in any order. Any face may be divided into several distinct parts and described like if it was more faces. Faces do not overlap. Every face has one inner side and one outer side. No side can be "partially inner and partially outer".

Each face is described on a single line. The line begins with an integer number P stating the number of points that determine the face, 4 <= P <= 200. Then there are 3 x P numbers, coordinates of the points. Each point is described by three coordinates X,Y,Z (0 <= X,Y,Z <= 1000) separated by spaces. The points are separated from each other and from the number P by two space characters. These additional spaces were added to make the input more human readable. The face can be constructed by connecting the points in the specified order, plus connecting the last point with the first one.

The face is always composed of "unit squares", that means every edge runs either in X, Y or Z-axis direction. If we take any two neighbouring points X1,Y1,Z1 and X2,Y2,Z2, then the points will always differ in exactly one of the three coordinates. I.e. it is either X1 <> X2, or Y1 <> Y2, or Z1 <> Z2, other two coordinates are the same. Every face lies in an orthogonal plane, i.e. exactly one coordinate is always the same for all points of the face. The face outline will never touch nor cross itself.

Output

Your program must print a single line for every test case. The line must contain the sentence The bulk is composed of V units., where V is the volume of the bulk.

Example

Sample Input:

2
12
4  10 10 10  10 10 20  10 20 20  10 20 10
4  20 10 10  20 10 20  20 20 20  20 20 10
4  10 10 10  10 10 20  20 10 20  20 10 10
4  10 20 10  10 20 20  20 20 20  20 20 10
4  10 10 10  10 20 10  20 20 10  20 10 10
5  10 10 20  10 20 20  20 20 20  20 15 20  20 10 20
4  14 14 14  14 14 16  14 16 16  14 16 14
4  16 14 14  16 14 16  16 16 16  16 16 14
4  14 14 14  14 14 16  16 14 16  16 14 14
4  14 16 14  14 16 16  16 16 16  16 16 14
4  14 14 14  14 16 14  16 16 14  16 14 14
4  14 14 16  14 16 16  16 16 16  16 14 16
12
4  20 20 30  20 30 30  30 30 30  30 20 30
4  10 10 10  10 40 10  40 40 10  40 10 10
6  10 10 20  20 10 20  20 30 20  30 30 20  30 40 20  10 40 20
6  20 10 20  20 20 20  30 20 20  30 40 20  40 40 20  40 10 20
4  10 10 10  40 10 10  40 10 20  10 10 20
4  10 40 10  40 40 10  40 40 20  10 40 20
4  20 20 20  30 20 20  30 20 30  20 20 30
4  20 30 20  30 30 20  30 30 30  20 30 30
4  10 10 10  10 40 10  10 40 20  10 10 20
4  40 10 10  40 40 10  40 40 20  40 10 20
4  20 20 20  20 30 20  20 30 30  20 20 30
4  30 20 20  30 30 20  30 30 30  30 20 30

Sample Output:

The bulk is composed of 992 units.
The bulk is composed of 10000 units.

Warning: large Input/Output data, be careful with certain languages


hide comments
tripodsan: 2023-01-16 14:50:27

I quite liked it. I created ply files of the two bulks (with the bottom side removed):
https://3dviewer.net/#model=https://gist.githubusercontent.com/tripodsan/e2c297007e806c2f575eb81c3ffe7c93/raw/eda5813f4a59c6582d4589925a3ea722754f0839/bulk0.ply
https://3dviewer.net/#model=https://gist.githubusercontent.com/tripodsan/efefc843839aa55ad9759e7dc44f4615/raw/5f0d04dbbf5965ef649be703d66637dab2296fc1/bulk1.ply
(note: at the time of writing, the 3dviewer can't properly render the faces with the L shape of the 2nd bulk)

hints: take into account that the faces are planar and the edges parallel to the axis

princebilly: 2019-10-04 07:57:10

What should I know before solving this problem?

khoaph: 2019-05-11 09:21:01

How to know if 2 paralel faces are in opposite direction?

Last edit: 2019-05-11 09:23:06
lnediak: 2019-02-01 02:51:38

lol I really am dumb. I worked so hard to implement a serious flood fill and then count the stuff, but I kept getting time limit exceeded. Finally, in desparation, I google how to solve the problem. Lo and behold, I see how to do it properly and scold myself for not noticing. LOLOLOL

jijucm: 2018-07-12 20:44:35

my solution works with the sample input given above. but results in "wrong answer" when submitted. Any idea friends ? Does any one know the input file used by online judge ?

nkumar_1896: 2017-03-20 14:27:41

can anyone help me, i don't understand the problem??

souvikdc: 2016-12-23 05:09:51

Can anyone please tell me that how a five edged face can have all the interior angles <=90 degrees and how all of its edges are parallel to the orthogonal plane?

ortemis: 2016-05-05 18:32:49

Here are models of the 2 examples in the sample input:
http://imgur.com/a/VHyhz

Zaf: 2016-04-18 11:27:07

If a face has a hole in it, it is described as 2 faces which touch each other but leave a hole between them.

Brian Bi: 2016-02-07 00:38:41

How is a face described if it has a hole in it?


Added by:adrian
Date:2004-05-08
Time limit:1s-7s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS PERL6 VB.NET
Resource:ACM Central European Programming Contest, Prague 2000