Strongly Connected Chemicals

View as PDF

Submit solution

Points: 1.54 (partial)
Time limit: 1.0s
Memory limit: 512M
Input: stdin
Output: stdout

Problem type
Allowed languages
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch

One type of chemical compounds is the ionic compound, because it is composed of positively charged ions (cations) and negatively charged ions (anions) in such a way that the compound as a whole is electrically neutral. Cations always attract anions and anions always attract cations.

Now you are given ~m~ cations and ~n~ anions, and their connectivity information about which cation attracts which anion. You task is to find a sub group from the cations and anions where there is at least one cation and at least one anion, such that all the cations in the group attract all the anions in the group. We call such a group as 'Strongly Connected Chemicals' . As there can be many such groups, we want to find a group which has the highest cardinality. Cardinality means the number of members (cation and anion) in the group.

Input

  • Input starts with an integer ~T \leq 100~ , denoting the number of test cases.
  • Each case starts with a line containing two integers: ~m~ and ~n~ (~1 \leq m~, ~n \leq 50~) . Each of the next ~m~ lines contains ~n~ characters (without space), each either ~0~ or ~1~ . If the ~j^{th}~ character in the ~i^{th}~ line is ~1~ , that means the ~i^{th}~ cation attracts the ~j^{th}~ anion, otherwise it doesn't.

Output

  • For each case, print the case number and the maximum possible size of the strongly connected chemical group.

Sample Input

2

3 4

1100

1110

0011

2 2

10

00

Sample Output

Case 1: 4
Case 2: 2

Comments

Please read the guidelines before commenting.


There are no comments at the moment.