// Simple HungaryAlgorithmTemplate question .. In this example, cows have the largest production capacity in their favorite columns, including n and M. Calculate the maximum output.
// If MK [I] = 0, it indicates that no access has been made. If it is set to 1, it indicates that no access has been made.
# Include <iostream>
# Include <stdio. h>
# Include <string. h>
Using namespace STD;
Const int maxn = 500;
Int MK [maxn];
Int NX, NY; // Number of vertices in the X and Y Sets
Int G [maxn] [maxn]; // adjacent matrix, edge information between vertices in X and Y Sets
Int CX [maxn], CY [maxn];
Int path (int u)
{
For (INT v = 1; v <= NY; V ++) // consider all Yi vertices v
{
If (G [u] [v] &! MK [v])
{
MK [v] = 1;
If (CY [v] =-1 | path (CY [v])
{
CX [u] = V; // match V to u
CY [v] = u; // match u to V
Return 1; // find the augmented path
}
}
}
Return 0; // if there is no augmented path from u
}
Int maxmatch () // calculate the Hungarian algorithm for maximum matching of Two Graphs
{
Int res = 0;
Int I;
Memset (CX, 0xff, sizeof (CX ));
Memset (CY, 0xff, sizeof (CY ));
For (I = 1; I <= NX; I ++)
{
If (CX [I] =-1) // search for augmented path from each uncovered point
{
Memset (MK, 0, sizeof (MK ));
Res + = path (I); // each time an augmented path is found, the matching number plus 1 is allowed.
}
}
Return res;
}
Int main ()
{
Int n, m;
Int I, J;
Int num, ans;
While (scanf ("% d", & N, & M )! = EOF)
{
Nx = N; ny = m;
Memset (G, 0, sizeof (g ));
For (I = 1; I <= N; I ++)
{
Scanf ("% d", & num );
For (j = 1; j <= num; j ++)
{
Scanf ("% d", & ANS );
G [I] [ANS] = 1;
}
}
Printf ("% d \ n", maxmatch ());
}
Return 0;
}