Cairo Corridor
Time limit2sMemory limit512 MB
Each tile is split into two pentagon halves; find the connected clear region touching all four borders and decide whether it is minimal.
- Level
Medium7 of 10
- Topics
- Graph, BFS, Implementation, Simulation
- Solved
- No attempts yet
Problem
The Cairo pentagonal tiling covers the plane with semiregular pentagons. It is named after Cairo, where several streets are paved with variations of the pattern.
Consider a bounded tiling in which every pentagon is either clear (white) or filled in (grey). A corridor is a maximal set of clear pentagons, connected to one another, that reaches all four borders of the tiling. Two pentagons are adjacent when they share an edge; sharing a single corner is not enough. A tiling has at most one corridor. A corridor is minimal when it has no superfluous pentagon, that is, when filling in any one pentagon of the corridor leaves a set that is no longer a corridor.

The figure shows four tilings. The first three have a corridor, drawn in yellow. The corridors of (a) and (b) are minimal, the corridor of (c) is not: fill in the tiles marked X, among others, and a corridor still exists. The rightmost tiling has no corridor. Tilings (a) and (c) are the two tilings of the first example.
For each tiling, decide whether a corridor exists and is minimal. When it is minimal, report the size of the corridor, that is, the number of clear pentagons in it.
Input
The first line contains the number of tilings . Each tiling starts with a line holding two integers and separated by a space. The next lines each contain binary digits that give the pairs of pentagons , , where 0 is a clear pentagon and 1 is a filled one. Line lists , , , , and so on up to .
Read the tiling as a grid of squares. The square in row and column holds one pair of pentagons. If is even, is the left half of that square and is the right half. If is odd, is the top half and is the bottom half. Horizontal pairs and vertical pairs therefore alternate like the squares of a checkerboard. Two pentagons are adjacent when their halves share a segment of positive length, and a pentagon reaches a border of the tiling when its half touches that side of the outer rectangle.
Output
Print lines. Line holds the size of the corridor of the -th tiling when that tiling has a minimal corridor, and NO MINIMAL CORRIDOR otherwise. Print the text NO MINIMAL CORRIDOR exactly as written.
Constraints
- , the number of tilings
- and for every tiling
- , the total number of grid lines
- , the total number of tile pairs per line