Courses

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 5411    Accepted Submission(s): 2597
Problem Description
Consider a group of N students and P courses. Each student visits zero, one or more than one courses. Your task is to determine whether it is possible to form a committee of exactly P students that satisfies simultaneously the conditions:



. every student in the committee represents a different course (a student can represent a course if he/she visits that course)



. each course has a representative in the committee



Your program should read sets of data from a text file. The first line of the input file contains the number of the data sets. Each data set is presented in the following format:



P N

Count1 Student1 1 Student1 2 ... Student1 Count1

Count2 Student2 1 Student2 2 ... Student2 Count2

......

CountP StudentP 1 StudentP 2 ... StudentP CountP



The first line in each data set contains two positive integers separated by one blank: P (1 <= P <= 100) - the number of courses and N (1 <= N <= 300) - the number of students. The next P lines describe in sequence of the courses . from course 1 to course P,
each line describing a course. The description of course i is a line that starts with an integer Count i (0 <= Count i <= N) representing the number of students visiting course i. Next, after a blank, you'll find the Count i students, visiting the course,
each two consecutive separated by one blank. Students are numbered with the positive integers from 1 to N.



There are no blank lines between consecutive sets of data. Input data are correct.



The result of the program is on the standard output. For each input data set the program prints on a single line "YES" if it is possible to form a committee and "NO" otherwise. There should not be any leading blanks at the start of the line.



An example of program input and output:
 
Sample Input
2
3 3
3 1 2 3
2 1 2
1 1
3 3
2 1 3
2 1 3
1 1
 
Sample Output
YES
NO
 
Source
 
Recommend
We have carefully selected several similar problems for you:  1068 2444 1150 1281 1045 

#include<stdio.h>
#include<string.h>
#include<vector>
#include<algorithm>
using namespace std;
int pipei[500],used[500];
vector<int>map[500];
int find(int x)
{
for(int i=0;i<map[x].size();i++)
{
int y=map[x][i];
if(!used[y])
{
used[y]=1;
if(!pipei[y]||find(pipei[y]))
{
pipei[y]=x;
return 1;
}
}
}
return 0;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m;
scanf("%d%d",&n,&m);
memset(pipei,0,sizeof(pipei));
for(int i=1;i<=n;i++)
map[i].clear();
for(int i=1;i<=n;i++)
{
int x,y;
int k;
scanf("%d",&k);
while(k--)
{
scanf("%d",&y);
map[i].push_back(y);
}
}
int sum=0;
for(int i=1;i<=n;i++)
{
memset(used,0,sizeof(used));
sum+=find(i);
}
if(sum==n)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}

hdoj--1083--Courses(最大匹配)的更多相关文章

  1. HDOJ 1083 Courses

    Hopcroft-Karp算法模板 Courses Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  2. hdoj 1083 Courses【匈牙利算法】

    Courses Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total S ...

  3. hdu 1083 Courses (最大匹配)

    CoursesTime Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  4. HDU 1083 Courses 【二分图完备匹配】

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1083 Courses Time Limit: 20000/10000 MS (Java/Others)  ...

  5. HUD——1083 Courses

    HUD——1083   Courses Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Ot ...

  6. hdu 1083 Courses(二分图最大匹配)

    题意: P门课,N个学生.     (1<=P<=100    1<=N<=300) 每门课有若干个学生可以成为这门课的代表(即候选人). 又规定每个学生最多只能成为一门课的代 ...

  7. HDU 1083 Courses(最大匹配模版题)

    题目大意: 一共有N个学生跟P门课程,一个学生可以任意选一 门或多门课,问是否达成:    1.每个学生选的都是不同的课(即不能有两个学生选同一门课)   2.每门课都有一个代表(即P门课都被成功选过 ...

  8. HDU 1083 - Courses - [匈牙利算法模板题]

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1083 Time Limit: 20000/10000 MS (Java/Others) M ...

  9. HDU - 1083 Courses /POJ - 1469

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1083 http://poj.org/problem?id=1469 题意:给你P个课程,并且给出每个课 ...

  10. hdu - 1083 - Courses

    题意:有P门课程,N个学生,每门课程有一些学生选读,每个学生选读一些课程,问能否选出P个学生组成一个委员会,使得每个学生代言一门课程(他必需选读其代言的课程),每门课程都被一个学生代言(1 <= ...

随机推荐

  1. chm文件打开无显示解决办法

    右键单击chm文件---属性---在该页面选择“解除锁定”---ok!

  2. Linux while和for循环简单分析

    一.循环重定向 最近遇到了一种新的循环重定向写法,由于没看懂,说以网上搜索了一下,然后再此分享一下: while read line do ...... done  < file 刚开始看,不明 ...

  3. CXF-JAX-WS开发(一)入门案例

    一.Web Service 1.定义 W3C定义,Web服务(Web service)应当是一个软件系统,用以支持网络间不同机器的互动操作. 2.作用 多系统间数据通信 二.CXF是什么? CXF是目 ...

  4. semiautomatic annotated tools

    在进行实验图像取样时,可能会用到大量的标签样本,拍摄大量图片进行手工标注要消耗大量时间,半自动化的标注工具可以节省一些时间. 原文链接:http://blog.sina.com.cn/s/blog_6 ...

  5. jquery的attr和prop

    注意不同版本的attr和prop,attr适用于自定义dom值,prop适用于带有固有属性

  6. [实战经验][SQL Sever 2008 (R)解决方法累积

    SQL Sever 2008 (R)的安装图解及配置 http://www.soft6.com/v9/2009/jcsj_1030/115821.html 产品密钥,选择“输入产品密钥”,输入:PTT ...

  7. C# 检测dll的新版本号方法

    FileVersionInfo info = FileVersionInfo.GetVersionInfo(YourFileNameHere);string version = info.FileMa ...

  8. .NET 解决方案 核心库整理

    一系列令人敬畏的.NET核心库,工具,框架和软件: https://www.cnblogs.com/weifeng123/p/11039345.html 企业级解决方案收录:  https://www ...

  9. 记Python学习

    上周学的Python,感觉有点忘了,现在回顾一下... 一.Python安装及测试:https://www.cnblogs.com/weven/p/7252917.html 例子: Python自带的 ...

  10. Nginx服务器部署SSL证书手机不信任解决方法

    在wosign申请证书并按指南正确部署证书后,如果发现PC浏览器访问正常,手机或safari浏览器提示证书不受信任,那肯定是在文件传输解压过程中导致证书文件中出现空格.乱码之类的情况,这里教您轻松四步 ...