#P3068. Party Invitations
Party Invitations
Party Invitations
Farmer John is hosting a party and he wants to invite as few cows as possible while ensuring that his loyal cow friends do not feel left out. In his herd, there are several groups of cows such that for any group of size \(k\), if \(k-1\) cows are invited then the last cow must also be invited. Note that the groups may overlap (but no two groups are identical) and can be of any size. Farmer John has decided that cow #1 is definitely invited. Given the description of the groups, determine the minimum number of cows that will end up being invited to the party.
Input Format:
- The first line contains two integers \(N\) and \(G\), where \(N\) (1 ≤ \(N\) ≤ 106) is the total number of cows, and \(G\) is the number of groups.
- Each of the following \(G\) lines describes a group. The line begins with an integer \(k\) (the number of cows in the group), followed by \(k\) distinct integers representing the cow numbers in that group. The sum of all group sizes is at most 250,000.
Output Format:
Output a single integer representing the minimum number of cows invited to the party.
Note: All formulas are given in \(\LaTeX\) format.
inputFormat
The first line contains two space‐separated integers \(N\) and \(G\). Each of the next \(G\) lines starts with an integer \(k\) (the number of cows in that group), followed by \(k\) space‐separated cow numbers. Cow numbers range from 1 to \(N\).
outputFormat
Output a single integer: the minimum number of cows that will be invited to the party.
sample
5 4
2 1 2
2 2 3
2 3 4
2 4 5
5