there are altogether N a student and P Door Courses , A student can choose any one
door or multiple courses , ask whether to achieve :
1. Each student is selected for a different class ( i.e. no two students can choose the same course )
2. Each course has a representative ( that is, P -Courses have been successfully selected )
Input as :
P N ( number of courses and number of students )
Then there are p line Span style= "Background-color:inherit;" >, count i student i +1 ... student count
(Count ; >1 Number of students interested count )
as in the first line 2 1 2 Show Students 1 with students 2 on the course 1 interested
output to :
If you can meet the above two requirements this output " YES ", Otherwise, the NO "
Note: It is a course matching student, the student is not OK in class ... ******************************************************************** #include < Stdio.h>
#include <string.h>
#include <algorithm>
usingnamespaceStd
ConstintMAXN =1005;
Constintoo = 1e9;
BOOLG[MAXN][MAXN], USED[MAXN];
intP[MAXN], N, M;///n Courses, M students
BOOLFind (intU
{
for(intI=1; i<=m; i++)
{
if(G[u][i] && used[i] = =false)
{
Used[i] =true;
if(P[i] = =false|| Find (P[i]))
{
P[i] = u;
returntrue;
}
}
}
returnfalse;
}
intMain ()
{
intT
scanf"%d", &t);
while(t--)
{
intI, V, Q;
memset (G,0,sizeof(G));
Memset (P,0,sizeof(p));
scanf"%d%d", &n, &m);
for(i=1; i<=n; i++)
{
scanf"%d", &q);
while(q--)
{
scanf"%d", &v);
G[I][V] =true;
}
}
for(i=1; i<=n; i++)
{
memset (Used,false,sizeof(used));
if(Find (i) = =false)
Break;
}
if(I <= N)
printf"no\n");
Else
printf"yes\n");
}
return0;
}
C-courses-hdu 1083 (template)