Party Invitations
Time limit1sMemory limit128 MB
Inviting cow 1 forces whole groups once all but one member is in; find the smallest set of cows that must be invited.
- Level
Medium7 of 10
- Topics
- Graph, BFS, Hash map, Implementation
- Solved
- No attempts yet
Problem
Farmer John is throwing a party and wants to invite some of his cows to show them how much he cares about his herd. Remembering all too well the disaster that resulted the last time he invited too many cows, he also wants to invite as few cows as possible.
Among FJ's cows there are certain groups of friends that are hard to separate. For any such group of size , if FJ invites at least of the cows in the group, then he must invite the final cow as well, thereby including the entire group. Groups can be of any size and may overlap, although no two groups contain exactly the same set of members. The sum of all group sizes is at most .
The cows are numbered through (with at most ), and FJ has decided that he must start by inviting cow . Given the groups among FJ's cows, determine the minimum number of cows FJ must invite to his party.
Input
- Line 1: Two space-separated integers (the number of cows) and (the number of groups).
- Lines : Each line describes a group. It begins with an integer , the size of the group, followed by the cows in the group (each an integer from to ).
Output
- Line 1: The minimum number of cows FJ must invite to his party.
Hint
In the sample there are cows and groups; the first group contains cows and .
In addition to cow , FJ must invite cow (because of the first group), cow (because of the second group), and cow (because of the last group), for a total of cows.