hdoj--1083--Courses(最大匹配)
Courses
. 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:
2
3 3
3 1 2 3
2 1 2
1 1
3 3
2 1 3
2 1 3
1 1
YES
NO
#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(最大匹配)的更多相关文章
- HDOJ 1083 Courses
Hopcroft-Karp算法模板 Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- hdoj 1083 Courses【匈牙利算法】
Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- hdu 1083 Courses (最大匹配)
CoursesTime Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- HDU 1083 Courses 【二分图完备匹配】
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1083 Courses Time Limit: 20000/10000 MS (Java/Others) ...
- HUD——1083 Courses
HUD——1083 Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- hdu 1083 Courses(二分图最大匹配)
题意: P门课,N个学生. (1<=P<=100 1<=N<=300) 每门课有若干个学生可以成为这门课的代表(即候选人). 又规定每个学生最多只能成为一门课的代 ...
- HDU 1083 Courses(最大匹配模版题)
题目大意: 一共有N个学生跟P门课程,一个学生可以任意选一 门或多门课,问是否达成: 1.每个学生选的都是不同的课(即不能有两个学生选同一门课) 2.每门课都有一个代表(即P门课都被成功选过 ...
- HDU 1083 - Courses - [匈牙利算法模板题]
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1083 Time Limit: 20000/10000 MS (Java/Others) M ...
- HDU - 1083 Courses /POJ - 1469
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1083 http://poj.org/problem?id=1469 题意:给你P个课程,并且给出每个课 ...
- hdu - 1083 - Courses
题意:有P门课程,N个学生,每门课程有一些学生选读,每个学生选读一些课程,问能否选出P个学生组成一个委员会,使得每个学生代言一门课程(他必需选读其代言的课程),每门课程都被一个学生代言(1 <= ...
随机推荐
- ★Java语法(五)——————————三元运算符
package 课上练习; public class 三元运算符 { //用法: 数据类型 变量 = 布尔表达式? 条件满足设置内容:条件不满足设置内容 : public static void ma ...
- 复习java第五天(枚举、Annotation(注释) 概述)
一.枚举 传统的方式: •在某些情况下,一个类的对象是有限而且固定的.例如季节类,只能有 4 个对象 •手动实现枚举类: —private 修饰构造器. —属性使用 private final 修饰. ...
- 使用GitGUI创建上传本地工程
参考链接: 使用Git-GUI创建工程 http://jingyan.baidu.com/article/27fa732683ebf546f8271f2e.html 一.刚创建的github版本库,在 ...
- js 记住我
$(function(){ $("#btn_login").click(function() { var anv=$("#an").val(); //登录名 v ...
- php 加密解密函数封装
算法一: //加密函数 function lock_url($txt,$key='yang') { $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghi ...
- python 直接存入Excel表格
def write_excels(self, document): outwb = openpyxl.Workbook() outws = outwb.create_sheet(index=0) fo ...
- 网络安全web部分
Web安全 一. SQL注入 1) 原理 通过构建特殊的输入作为参数传入Web应用程序,而这些输入大都是SQL语法里的一些组合,通过执行SQL语句进而执行攻击者所要的操作,其主要原因是程序 ...
- eclipse导入Javaweb文件出错解决
在项目名上右击打开properties,如图在箭头指的位置可以看出有个unbound表示导入的资源库出现 异常,需要手动导入,1.点击Server Library{Apache Tomcat v9.0 ...
- iptables 实现内网转发上网
介绍 通过iptables做nat转发实现所有内网服务器上网. 操作 首先开启可以上网的服务器上的内核路由转发功能.这里我们更改/etc/sysctl.conf 配置文件. [root@web1 /] ...
- 移动端rem.js使用方法
下面的代码一是我根据rem的使用经验,自己写的一个rem.js,发现很好用,能适用所有移动端h5页面的自适应需求: 代码一: ``` window.onload = function(){ /*720 ...