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

Input

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

P N

Count1 Student 1 1 Student 1 2 ... Student 1 Count1

Count2 Student 2 1 Student 2 2 ... Student 2 Count2

...

CountP Student P 1 Student P 2 ... Student P 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抣l 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.

Output

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.

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

判断每个课程能不能都匹配上人,二分图匹配

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+100;
const double eps=1e-8;
using namespace std;
const double pi=acos(-1.0);
const int inf=0xfffffff;
const int N=305;
int n,m;
int line[N][N],visit[N],connect[N];
bool find(int x)
{
rep(i,1,m+1)
{
if(line[x][i]&&visit[i]==0)
{
visit[i]=1;
if(connect[i]==0||find(connect[i]))
{
connect[i]=x;
return true;
}
}
}
return false;
}
int main()
{
int re,x,p;
sf("%d",&re);
while(re--)
{
int ans=0;
mm(line,0);
mm(connect,0);
sf("%d%d",&n,&m);
rep(i,1,n+1)
{
sf("%d",&p);
while(p--)
{
sf("%d",&x);
line[i][x]=1;
}
}
rep(i,1,n+1)
{
mm(visit,0);
if(find(i)) ans++;
}
if(ans==n) pf("YES\n");
else pf("NO\n");
}
return 0;
}

M - COURSES的更多相关文章

  1. poj 2239 Selecting Courses (二分匹配)

    Selecting Courses Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8316   Accepted: 3687 ...

  2. POJ 1469 COURSES

    COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20478   Accepted: 8056 Descript ...

  3. HDOJ 1083 Courses

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

  4. Courses

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

  5. HDU-----(1083)Courses(最大匹配)

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

  6. POJ 1469 COURSES(二部图匹配)

                                                                     COURSES Time Limit: 1000MS   Memory ...

  7. Doing well in your courses ---- a guide by Andrej Karpathy

    Doing well in your courses a guide by Andrej Karpathy Here is some advice I would give to younger st ...

  8. Windows Kernel Security Training Courses

    http://www.codemachine.com/courses.html#kerdbg Windows Kernel Internals for Security Researchers Thi ...

  9. poj 1469 COURSES(匈牙利算法模板)

    http://poj.org/problem?id=1469 COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions:  ...

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

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

随机推荐

  1. poj2456 Aggressive cows(二分查找)

    https://vjudge.net/problem/POJ-2456 二分,从最大长度开始,不断折半试,如果牛全放下了,就是可行,修改下界,否则改上届. #include<iostream&g ...

  2. 【Java】maven多项目资源共享

    方案一: <resources> <resource> <!-- <directory>${project.parent.relativePath}/../. ...

  3. 新版本的bettercap不好用, 如何安装和编译旧版本的bettercap

    新版本的bettercap2.0以上是用go语言写的, 各种功能感觉还不太完善, 没有原来的用ruby写的好, 想着回退安装bettercap1.6旧版本 系统环境: kali 2017.2 下载源码 ...

  4. 通过自己定义MVC的Controller的Json转换器解决日期序列化格式问题

    今日,在MVC框架下使用EasyUI的datagrid载入数据时,服务端返回的Json日期格式为 /Date(1433088000000+0800)/ .须要client进一步转换.并且也不符合Eas ...

  5. 关于inodes占用100%解决方法

    df -i; 发现inode节点占满: 这个时候如果不知道哪儿节点占用多可以用下边的脚本进行检查,查看到底哪个目录下面的文件最多: for i in /*; do echo $i; find $i | ...

  6. maven在Idea建立工程,运行出现Server IPC version 9 cannot communicate with client version 4错误

    问题的根源在于,工程当中maven dependencies里面的包,有个hadoop-core的包,版本太低,这样,程序里面所有引用到org.apache.hadoop的地方,都是低版本的,你用的是 ...

  7. 开发app前需要提前准备的资料

    需要准备的资料整理如下: 1 域名未注册,建议在 阿里云注册:https://www.aliyun.com/,2 服务器https://ecs-buy.aliyun.com/配置:计费方式:包年包月地 ...

  8. SQL Server 性能优化实战系列(一)

    数据库服务器主要用于存储.查询.检索企业内部的信息,因此需要搭配专用的数据库系统,对服务器的兼容性.可靠性和稳定性等方面都有很高的要求.        下面是进行笼统的技术点说明,为的是让大家有一个整 ...

  9. 时间序列异常检测算法S-H-ESD

    1. 基于统计的异常检测 Grubbs' Test Grubbs' Test为一种假设检验的方法,常被用来检验服从正太分布的单变量数据集(univariate data set)\(Y\) 中的单个异 ...

  10. OLT、分光器、ONU直接的关系