Question meaning:
There are N students and P courses, allowing you to determine whether it can constitute the maximum match.
Enter a T to indicate that there are T groups of test data;
In input N and P, P indicates there are P courses, and N indicates there are N students.
Followed by P rows, such:
A a1 a2 a3 a4 a5 --- the first line. 1 matches with a1, a2, a3, a4, and a5.
B b1 b2 b3 ----- Row 2. B matches with b1, b2, and b3.
YES if the number of matched students is equal to the number of students;
Otherwise, it is NO;
[Cpp]
# Include "stdio. h"
# Include "string. h"
# Define N 501
Int n, m, map [N] [N], mark [N], link [N];
Int dfs (int t)
{
Int I;
For (I = 1; I <= m; I ++)
{
If (! Mark [I] & map [t] [I])
{
Mark [I] = 1;
If (link [I] =-1 | dfs (link [I])
{
Link [I] = t;
Return 1;
}
}
}
Return 0;
}
Int MaxMatch ()
{
Int I, num;
Num = 0;
Memset (link,-1, sizeof (link ));
For (I = 1; I <= m; I ++)
{
Memset (mark, 0, sizeof (mark ));
If (dfs (I ))
Num ++;
}
Return num;
}
Int main ()
{
Int I, j, a, B, T, ans;
Scanf ("% d", & T );
While (T --)
{
Scanf ("% d", & n, & m );
Memset (map, 0, sizeof (map ));
For (I = 1; I <= n; I ++)
{
Scanf ("% d", & );
For (j = 0; j <a; j ++)
{
Scanf ("% d", & B );
Map [I] [B] = 1;
}
}
Ans = MaxMatch ();
// Printf ("% d \ n", ans );
If (MaxMatch () = n)
Printf ("YES \ n ");
Else
Printf ("NO \ n ");
}
Return 0;
}