Students have their own favorite courses. Therefore, for a course, multiple students may like it, but we want to have candidates for none of them. The first data indicates the number of tests, followed by P courses and N students,
In the next row of P, the first letter represents course 1, 2... P. the first letter of each line of I is the student who loves this subject. Enter the student ID.
Output: if the request is met, "yes" is output; otherwise, "no" is output ".
Analysis:
This is a allocation problem. Naturally, we think of the maximum matching of a bipartite graph. A course is a collection, and a student is a collection. There are multiple associations between students and courses, but between students and students, and between courses. This is easy to do. Use the Hungarian arithmetic to obtain the maximum number of matches. As long as the number of matches is greater than or equal to the total number of subjects.
# Include "stdio. H"
# Include "string. H"
Int map [1000] [1000];
Int link [1000], Mark [1000];
Int n, m;
Int find (int K)
{
Int I;
For (I = 1; I <= m; I ++)
{
If (MARK [I] = 0 & map [k] [I])
{
Mark [I] = 1;
If (link [I] =-1 | find (link [I])
{
Link [I] = K;
Return 1;
}
}
}
Return 0;
}
Int main ()
{
Int I, K, H, P;
Scanf ("% d", & P );
While (p --)
{
Scanf ("% d", & N, & M );
Memset (MAP, 0, sizeof (MAP ));
Memset (link,-1, sizeof (Link ));
For (I = 1; I <= N; I ++)
{
Scanf ("% d", & K );
While (k --)
{
Scanf ("% d", & H );
Map [I] [H] = 1;
}
}
Int sum = 0;
For (I = 1; I <= N; I ++)
{
Memset (mark, 0, sizeof (Mark ));
Sum + = find (I );
}
If (sum = N)
Printf ("Yes \ n ");
Else
Printf ("NO \ n ");
}
Return 0;
}