Cow Conundrum
Irhas is in charge of managing a herd of cows, and he is stressed out since many of them don't seem to be eating as much they should. He has cows and
feeding troughs, and each cow will visit a subset of feeding troughs throughout the day. Irhas has bought some GoPros and wants to make sure he records every single interaction between a cow and a feeding trough.
If he puts a GoPro on a cow, it will capture every interaction between itself and all the troughs it visits. If he puts a GoPro on a feeding trough, it will capture its interactions with every cow that visits it. How many GoPros does Irhas need at minimum to cover every single cow/feeding trough interaction? These cameras are expensive and he wants to spend as little as possible.
It is possible for no cows to visit a trough, or a cow to visit no troughs, we regard these as having no interactions, and don't need to monitor them with cameras.
Input
The first line contains two integers and
, the number of cows and the number of troughs, labelled
and
respectively.
The next lines come in pairs, detailing the troughs each cow will visit. The first line of each pair contains a single number
, the number of troughs the
th cow will visit throughout the day. The next line contains
space-separated integers
, each trough that this cow will visit.
The trough numbers are unique in each line. The total number of cow/trough interactions (i.e., the sum of all s) will not exceed
.
Output
Output the minimum number of cameras Irhas needs to buy to make sure every interaction between a cow and a trough is recorded. Irhas can either place the cameras on cows or on troughs, following the rules above.
Example
Input 1
3 3
2
1 2
1
3
1
3
Output 1
2
In this case, it is optimal to place a camera on cow , and on trough
. This will ensure that all interactions are covered.
Input 2
4 5
3
1 4 5
1
2
2
2 3
1
3
Output 2
3
Here it is optimal to place cameras on cow , and troughs
and
.
Comments