CF1387C Viruses
Description
Viruses are detected by antibodies that identify the presence of specific continuous fragments of zeros and ones in the viruses' codes. For example, an antibody reacting to a fragment $ \\langle 0\\ 0\\ 1\\ 0\\ 0 \\rangle $ will detect a virus $ \\langle 0\\ 0\\ 1\\ 0\\ 0\\ 1\\ 0\\ 1 \\rangle $ , but it will not detect a virus $ \\langle 0\\ 1\\ 0\\ 1\\ 0\\ 0\\ 1\\ 0\\ 1 \\rangle $ .
For each gene from $ 2 $ to $ G-1$$$, the scientists are wondering whether a given set of antibodies is enough to detect all viruses that can emerge through mutations from this gene. If not, they want to know the length of the shortest virus that cannot be detected. It may happen that sometimes scientists don't have any antibodies. Then of course no virus can be detected, so the scientists are only interested in the length of the shortest possible virus that can emerge from the gene mutations.
Input Format
The sum of all values $ k $ does not exceed $ 100 $ . Every integer from $ 2 $ to $ G - 1 $ appears in the table as $ a $ at least once.
The next $ M $ lines contain descriptions of the antibodies; each such line begins with an integer $ \\ell $ ( $ \\ell \\geq 1 $ ), followed by a sequence of $ \\ell $ integers $ c\_1, c\_2, \\ldots, c\_\\ell $ ( $ 0 \\leq c\_i \\leq 1 $ ), describing the antibody. The sum of all values $ \\ell $ does not exceed $ 50$$$.