onsider 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:

Input

2
3 3
3 1 2 3
2 1 2
1 1
3 3
2 1 3
2 1 3
1 1

Output

YES
NO

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
第一题二分图啊,wa了6遍,后来a了还是不知道当时为啥wa了
题意:学科与学生匹配,学生必须要有匹配,学科不一定。
解法:匈牙利算法计数就ok了
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007 using namespace std; const double eps=1e-;
const int N=,maxn=,inf=0x3f3f3f3f; bool ok[maxn][maxn],used[maxn];
int vis[maxn],n,m,t; bool match(int x)
{
for(int i=;i<=m;i++)
{
if(!used[i]&&ok[x][i])
{
used[i]=;
if(vis[i]==-||match(vis[i]))
{
vis[i]=x;
return ;
}
}
}
return ;
}
int main()
{
cin>>t;
while(t--){
cin>>n>>m;
bool flag=;
memset(ok,,sizeof(ok));
for(int i=;i<=n;i++)
{
int k,a;
cin>>k;
if(k==)flag=;
while(k--){
cin>>a;
ok[i][a]=;
}
}
memset(vis,-,sizeof(vis));
int i,num=;
for(i=;i<=n;i++)
{
memset(used,,sizeof(used));
if(!match(i))break;
}
if(i==n+)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return ;
}

hdu1083二分图匹配模板题的更多相关文章

  1. HDU - 1054 Strategic Game (二分图匹配模板题)

    二分图匹配模板题 #include <bits/stdc++.h> #define FOPI freopen("in.txt", "r", stdi ...

  2. HDU-2063(二分图匹配模板题)

    过山车Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...

  3. 【二分图裸题】poj1325机器调度

    题目大意:有两个机器A和B,A机器有n个模式,B机器有m个模式,两个机器最初在0模式 然后有k个作业,每个作业有三个参数i,a,b i代表作业编号,a和b代表第i作业要么在A机器的a模式下完成[或者] ...

  4. POJ 3041 Asteroids(二分图模板题)

    Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N g ...

  5. 【HDU 2063】过山车(二分图最大匹配模板题)

    题面 RPG girls今天和大家一起去游乐场玩,终于可以坐上梦寐以求的过山车了.可是,过山车的每一排只有两个座位,而且还有条不成文的规矩,就是每个女生必须找个个男生做partner和她同坐.但是,每 ...

  6. Asteroids(二分图最大匹配模板题)

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12323   Accepted: 6716 Description Bess ...

  7. 51nod 2006 飞行员配对(二分图最大匹配) 裸匈牙利算法 求二分图最大匹配题

    题目: 题目已经说了是最大二分匹配题, 查了一下最大二分匹配题有两种解法, 匈牙利算法和网络流. 看了一下觉得匈牙利算法更好理解, 然后我照着小红书模板打了一遍就过了. 匈牙利算法:先试着把没用过的左 ...

  8. HDU 1083 Courses(二分图匹配模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=1083 题意:有p门课和n个学生,每个学生都选了若干门课,每门课都要找一个同学来表演,且一个同学只能表演一门课,判 ...

  9. Kuhn-Munkres算法。带权二分图匹配模板 (bin神小改版本)

    /****************************************************** 二分图最佳匹配 (kuhn munkras 算法 O(m*m*n)). 邻接矩阵形式 . ...

随机推荐

  1. 引用类型-----Object

    本文章转载至:https://segmentfault.com/a/1190000003984584 关于引用类型的概念: 引用类型:引用类型的值(对象)是引用类型的一个实例: 对象:是某个特定引用类 ...

  2. WebSocket数据包协议详解

    其实我一直想不明白HTML5包装个应用层办议作为Socket通过基础目的是为了什么,其实直接支持Socket tcp相对来说更加简单灵活.既然标准已经制定而浏览器也支持那对于我们开发者来说只能用的分. ...

  3. Hive(笔记)

    (2015.07.22Hive笔记) 一.Hive的安装 1.1Hive的安装过程 下载hive源文件(apache-hive-0.14.0-bin.tar.gz ) 解压hive文件 进入$HIVE ...

  4. pyqt样式表语法笔记(上) --原创

    pyqt样式表语法笔记(上) pyqt QSS python 样式表 因为软件课设的原因开始学习使用pyqt4,才发现原来它也有样式表,而且语法跟css基本相同,而且一些功能实现起来感觉比js要简单方 ...

  5. empty 语句

    empty 语句: 用来表明没有语句, 尽管JavaScript语法希望有语句会被执行. empty语句 用分号表示 (;) ,用来指明没有语句会被执行, 尽管此时JavaScript语法需要执行语句 ...

  6. iOS性能之其他

    本篇文章是个引用,因为这些技术我都只是研究过,但是并没有在项目中使用,也没有深入研究,所以只能当做一个笔记了 网络请求 现在大多数的网络请求都是使用的json格式(相信没有APP再使用XML格式了吧) ...

  7. [微信小程序]初试——成绩分析小程序问题总结

    文件类型说明 第一次打开微信小程序的开发者工具,就是下面这个样子. 好多已经存在的默认文件 .js .json .wxml .wxss 首先当然要搞懂这些文件都是干什么的 app.js是小程序的脚本代 ...

  8. bootstrap使用模板

    Bootstrap下载地址: - https://github.com/twbs/bootstrap/releases/download/v3.3.6/bootstrap-3.3.6-dist.zip ...

  9. WebStorm里使用注意点

    归纳一些我在使用webstorm里遇到的问题: 1.问题:文件出现红线,如图 解决方案:可能是由于语言版本的问题,改一下版本试试 2.快捷键:http://www.cnblogs.com/yeming ...

  10. 【Electron】Electron开发入门(六):项目生成setup安装程序

    把electron发布的exe打包成setup安装程序,需要使用nsis软件, nsis打包的详细教程,可以参考我的这篇文章: win7下nsis打包exe安装程序教程