DOCTOR - The Cow Doctor
Texas is the state having the largest number of cows in the US: according to the 2005 report of the National Agricultural Statistics Service, the bovine population of Texas is 13.8 million. This is higher than the population of the two runner-up states combined: there are only 6.65 million cows in Kansas and 6.35 millions cows in Nebraska.
There are several diseases that can threaten a herd of cows, the most feared being "Mad Cow Disease" or Bovine Spongiform Encephalopathy (BSE); therefore, it is very important to be able to diagnose certain illnesses. Fortunately, there are many tests available that can be used to detect these diseases.
A test is performed as follows. First a blood sample is taken from the cow, then the sample is mixed with a test material. Each test material detects a certain number of diseases. If the test material is mixed with a blood sample having any of these diseases, then a reaction takes place that is easy to observe. However, if a test material can detect several diseases, then we have no way to decide which of these diseases is present in the blood sample as all of them produce the same reaction. There are materials that detect many diseases (such tests can be used to rule out several diseases at once) and there are tests that detect only a few diseases (they can be used to make an accurate diagnosis of the problem).
The test materials can be mixed to create new tests. If we have a test material that detects diseases A and B; and there is another test material that detects diseases B and C, then they can be mixed to obtain a test that detects diseases A, B, and C. This means that if we have these two test materials, then there is no need for a test material that tests diseases A, B, and C-such a material can be obtained by mixing these two.
Producing, distributing, and storing many different types of test materials is very expensive, and inmost cases, unnecessary. Your task is to eliminate as many unnecessary test materials as possible. It has to be done in such a way that if a test material is eliminated, then it should be possible to mix an equivalent test from the remaining materials. ("Equivalent" means that the mix tests exactly the same diseases as the eliminated material, not more, not less).
Input
The input contains several blocks of test cases. Each case begins with a line containing two integers: the number 1 <= n <= 300 of diseases, and the number 1 <= m <= 200 of test materials. The next m lines correspond to the m test materials. Each line begins with an integer, the number 1 <= k <= 300 of diseases that the material can detect. This is followed by k integers describing the k diseases. These integers are between 1 and n .
The input is terminated by a block with n = m = 0 .
Output
For each test case, you have to output a line containing a single integer: the maximum number of test materials that can be eliminated.
Example
Input: 10 5 2 1 2 2 2 3 3 1 2 3 4 1 2 3 4 1 4 3 7 1 1 1 2 1 3 2 1 2 2 1 3 2 3 2 3 1 2 3 0 0 Output: 2 4Warning: large input/output data, be careful with certain languages
hide comments
:D:
2010-08-01 13:05:17
There's something wrong with the input file format. As long as you're using scanf or reading char by char it should be ok. I didn't check for the input stream. Last edit: 2010-11-28 00:39:58 |
Added by: | Fudan University Problem Setters |
Date: | 2008-07-24 |
Time limit: | 2s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: C99 ERL JS-RHINO NODEJS PERL6 VB.NET |
Resource: | ACM Central European Programming Contest, Budapest 2005 |