7148. Magic Traps
Constraints
Time Limit: 1 secs, Memory Limit: 256 MB
Description
Rikka is fighting against Priestess in a park now, but it seems that she almost fails. The only thing she can do is to launch the magic traps which were deployed before. Each trap belongs to one of the three categories: rectangle, circle and triangle. Different categories of traps need different magic spells to launch. So Rikka must quickly understand how many traps of each category are there. Unfortunately, it's hard to understand what this trap category is for Rikka, so she needs your help.
To simplify the problem, we assume that the park is a large rectangle and divided into N*M blocks. A magic trap is combined by several connected blocks. Two blocks connect each other if and only if they share either an edge or a point. A block is said to be magic if it is part of a trap.
Because of her great power, Priestess can break some magic blocks so that they are not magic any more. Priestess can break a magic block only if it shares edges with at least two other magic blocks. For example, in the following figure, assume that block 1, 2, 3, 4, and 5 are all magic, while block 6 is not. Then block 5 cannot be broken because it shares an edge with only one magic block (block 3). Priestess can break one of block 1, 2, 3, or 4; however, she cannot break both block 1