C-courses-hdu 1083 (template)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.