Cube Painting
Sara was presented with a new Lego-like game as her birthday gift. This game, Unbounded Imaginations (UI), contains lots of uniform cubes such that each side of these cubes has an area of 1 cm2. The special attribute of UI is that someone can fix two cubes, side by side, with special glue such that two mentioned sides fit each other exactly. Dara as her big brother has decided to design a problem for Sara using UI. He constructs a 3D object by using these cubes and wants Sara to paint every side which is not coupled. We say a side is not coupled if it is not connected to another cube. For example imagine the object is something like this:
In the above example, sum of all not coupled sides is 16. The problem is to find out this number which shows how much area Sara should paint.
Specifications
Input
The first line of input contains a single integer which is the number of test cases. Following, there are data lines for test cases. Each test case begins with a line containing one integer N (1 <= N <= 200), which is the number of cubes. Cubes are numbered from 1 to N.
Next N lines describe formations of the object(s): connection data for each cube in one line. Each of these lines begins with an integer I, which is a cube number, followed by a colon character ":" and a blank, followed by some integers (at most six) which are the cubes connected to I, and finally followed by a single zero character "0" indicating the end of set. It is guaranteed that data for each test case realizes a valid object in space. Note that for each test case, cubes can construct any complex object or even multiple small separated objects.
Output
There should be one line for each test case which should contain a single integer, the sum of not coupled sides of all cubes for the corresponding test case.
Problem information
Time Limit: 1 secondsMemory Limit: 64 MB
Balls for the passed test: 10
Complexity: 16% 93/111
Example
Example input3 4 1: 2 3 0 2: 1 4 0 3: 4 1 0 4: 2 3 0 3 1: 2 0 2: 3 1 0 3: 2 0 4 1: 2 0 2: 1 0 3: 4 0 4: 3 0 |
Example output16 14 20 |
| ← LeChuck’s Revenge | Problems | Gold, Food and Power → |
