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. 外卖ERP管理系统(一)

    京门时代外卖ERP是北京京门时代科技有限公司旗下一款专业的外卖ERP系统管理软件. 本ERP目前己经对接了百度.饿了么.美团以等各外卖平台,在配送方面对接了闪送快递.人人快递.UU跑腿以及达达配送. ...

  2. Win 10 System Restore Fail 0x80070091

    Question: Below about says it all.  I tried SysRes from two points, both with same failure. System R ...

  3. vue项目启动时将localhost替换成指定ip地址

    1.node启动vue项目时地址一般都是http://localhost:8080 2.config->index.js 中的host:‘localhost’换成host:‘你的本机ip’就可以 ...

  4. [转]恕我直言,在座的各位根本不会写 Java!

    导语 自 2013 年毕业后,今年已经是我工作的第 4 个年头了,总在做 Java 相关的工作,终于有时间坐下来,写一篇关于 Java 写法的一篇文章,来探讨一下如果你真的是一个 Java 程序员,那 ...

  5. go微服务框架go-micro深度学习(一) 整体架构介绍

    产品嘴里的一个小项目,从立项到开发上线,随着时间和需求的不断激增,会越来越复杂,变成一个大项目,如果前期项目架构没设计的不好,代码会越来越臃肿,难以维护,后期的每次产品迭代上线都会牵一发而动全身.项目 ...

  6. 关于CALayer导致的crash问题

    push到一个页面进行绘图时,设置如下: CALayer * layer = [CALayer layer]; layer.frame = CGRectMake(, , , ); layer.dele ...

  7. 树莓派进阶之路 (038) - P2P 文件下载机

    硬件要求: 树莓派开发板 USB外接硬盘 一. Together 1. 更新安装程序 sudo apt-get update sudo apt-get upgrade sudo apt-get ins ...

  8. vue2 枚举类型转换

    vue2页面上要把数字0,1,2...之类的数值转换成对应的枚举文本,解决如下: 方案一: 如果是是否的问题,直接: {{enable == 1 ? '是' : '否'}} 即可. 方案二: 通过定义 ...

  9. Mathematica绘制曲面交线方法(方法二)

    MeshFunction方式 Show[Graphics3D[{Opacity[0.5], Ball[{0, 0, 0}, 2]}], ParametricPlot3D[{4 + (3 + Cos[v ...

  10. “2014年CityEngine三维建模与设计精英培训班”——全国巡回举办

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYXJjZ2lzX2FsbA==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...