HDU1083(最大匹配)
Courses
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5414 Accepted Submission(s): 2600
. 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:
3
#include"cstdio"
#include"cstring"
#include"vector"
using namespace std;
const int MAXN=;
int P,N;
vector<int> G[MAXN*+];
int match[MAXN*+];
int vis[MAXN*+];
void add_edge(int u,int v)
{
G[u].push_back(v);
G[v].push_back(u);
}
bool dfs(int u)
{
vis[u]=;
for(int i=;i<G[u].size();i++)
{
int v=G[u][i],w=match[v];
if(w<||(!vis[w]&&dfs(w)))
{
match[u]=v;
match[v]=u;
return true;
}
}
return false;
}
int bipartite_matching()
{
memset(match,-,sizeof(match));
int ans=;
for(int i=;i<=P;i++)
{
if(match[i]<)
{
memset(vis,,sizeof(vis));
if(dfs(i)) ans++;
}
}
return ans;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
for(int i=;i<MAXN*+;i++) G[i].clear();
scanf("%d%d",&P,&N);
for(int i=;i<=P;i++)
{
int s;
scanf("%d",&s);
while(s--)
{
int v;
scanf("%d",&v);
add_edge(i,v+MAXN);
add_edge(v+MAXN,i);
}
}
int ans=bipartite_matching();
if(ans==P) printf("YES\n");
else printf("NO\n");
} return ;
}
HDU1083(最大匹配)的更多相关文章
- HDU1083 Courses —— 二分图最大匹配
题目链接:https://vjudge.net/problem/HDU-1083 Courses Time Limit: 20000/10000 MS (Java/Others) Memory ...
- HDU-1083 Courses 二分图 最大匹配
题目链接:https://cn.vjudge.net/problem/HDU-1083 题意 有一些学生,有一些课程 给出哪些学生可以学哪些课程,每个学生可以选多课,但只能做一个课程的代表 问所有课能 ...
- hdu2063+hdu1083(最大匹配数)
传送门:hdu2063过山车 #include <cstdio> #include <cstring> #include <string> #include < ...
- HDU1083(KB10-C 二分图最大匹配)
Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- COURSES---poj1469 hdu1083(最大匹配)
题目链接:http://poj.org/problem?id=1469 http://acm.hdu.edu.cn/showproblem.php?pid=1083 题意:有n个学生p门课, 每门 ...
- HDU1083(二分图最大匹配vector实现)
Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- HDU-1083-Courses(最大匹配)
链接: https://vjudge.net/problem/HDU-1083#author=HUCM201732 题意: 题目大意: 一共有N个学生跟P门课程,一个学生可以任意选一 门或多门课,问是 ...
- Python学习实践------正向最大匹配中文分词
正向最大匹配分词: 1.加载词典文件到集合中,取词典文件中最大长度词的length 2.每次先在句子中按最大长度分割,然后判断分割的词是否存在字典中,存在则记录此词,调整起始点. 3.不存在则按最大长 ...
- UOJ79 一般图最大匹配
题目描述 从前一个和谐的班级,所有人都是搞OI的.有 nn 个是男生,有 00 个是女生.男生编号分别为 1,-,n1,-,n. 现在老师想把他们分成若干个两人小组写动态仙人掌,一个人负责搬砖另一个人 ...
随机推荐
- 解题报告 之 HDU5288 OO' s Sequence
解题报告 之 HDU5288 OO' s Sequence Description OO has got a array A of size n ,defined a function f(l,r) ...
- dubbo学习之Hello world
现在企业中使用dubbo的越来越多,今天就简单的学习一下dubbo,写了一个hello world,教程仅供入门,如要深入学习请上官网 服务提供方: 首先将提供方和消费方都引入jar包,如果使用的是m ...
- 爬虫基本操作、requests和BeautifulSoup
1. 爬虫基本操作 例如舆情系统: 获取汽车之家新闻放到自己数据库里,创建自己的app,发布内容,注明来源,自己创业. URL指定内容获取到 - 发送Http请求:http://www.autohom ...
- VS2010/12多核编译
在工作中,我们的一个完整的项目肯定是由多个个解决方案组成的,我们在调试的时候就会不断的去编译修改过的解决方案,如果当修改的解决方案多了以后我们编译的速度就在很大的程度上决定了我们的工作效率.这时候我们 ...
- AMD单双桥时序简叙
芯片组(双桥)时序 VBAT :RTC电路的供电3V(RTC电路有问题会导致没复位或不跑码等故障) RTCCLK :晶振起振给南桥提供32.768KHz频率(RTC电路有问题会导致没复位或不跑码等故障 ...
- UVA1422-Processor(二分法+优先队列)
option=com_onlinejudge&Itemid=8&category=512&page=show_problem&problem=4168"> ...
- 记录一次在 VirtualBox的添加共享windows文件后,发现没有共享文件的事
在VirtualBox设置完桥接添加ip后,在设备中添加共享windows文件,“e:\work ”,发现共享目录没有文件.使用了各种reboot之后,还是没有发现共享文件夹,重新设置还是不行,用mo ...
- linux的su和sudo(转载)
来源:http://www.jb51.net/LINUXjishu/12713.html 一. 使用 su 命令临时切换用户身份 1.su 的适用条件和威力 su命令就是切换用户的工具,怎么理解呢?比 ...
- 无法启动FTP站点,服务目前停止
在本地搭建了一个FTP服务器(windows搭建FTP服务器实战),再启动的时候提示错误: 错误提示信息: 根据提示可以查出问题原因:FTP服务没有开启 启动服务,再次重启站点服务.一切OK. 亲测好 ...
- 配置tomcat,访问端口改为80
首先:找到tomcat的的config文件夹下的server.xml文件: 编辑server.xml 保存server.xml文件,重启tomcat服务器,即可. 亲测好使.