Matrix and volume

0

0 votes
Hard, Graphs, Graph Theory, Algorithms, Algorithms, Graph, Depth First Search, Open, Depth First Search
Problem

You are given a large box of length X, width Y, and height Z. This box is entirely made up of small cubic boxes of 1 unit volume each which means that the length of the cube is 1 unit. Some cubes are removed to create empty spaces. All the cubes that are not removed stay fixed in their initial position.

Now, you are given information about the new state of the large box. In other words, you are given the status of each cube that is used to make the larger box. If the status is 1, then it means that this cubic block is not removed. If the status is 0, then it corresponds to the fact that this cubic block is removed.

Notes

  • Two blocks are adjacent if they share a face.
  • A cube whose size of the edge is 1 contains 1 unit cube volume.

If all the empty space is filled with air, then your task is to determine the volume of air that can stay trapped inside the box in the new state. The trapped air means that it should not come outside the box in an infinite amount of time.

Input format

  • First line: T denoting the number of test cases
  • For each test case:
    • First line: X,Y,Z representing the length, width, and height of the box
    • You are also given with the Z sets of XY 2D matrices each representing a layer of the box.

Output format
In a single line, print the volume of air that can be trapped.

Constraints

1T10

1X,Y,Z102

0Ai,j,k1

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In example 2 : 6 units of air volume can stay trapped in the box.

Editor Image

?