Courses
Courses
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2681 Accepted Submission(s): 1238
Problem Description
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
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:
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
Source
Southeastern Europe 2000
#include<stdio.h>
#include<string.h>
int P,N;
bool G[][],visit[];
int match[];
bool DFS(int k)
{
int t;
for (int i=;i<=N;i++)
if (G[k][i] && !visit[i])
{
visit[i]=;
t=match[i];
match[i]=k;
if (t==- || DFS(t)) return true;
match[i]=t;
}
return false;
}
int Max_match()
{
int ans=;
memset(match,-,sizeof(match));
for (int i=;i<=P;i++)
{
memset(visit,,sizeof(visit));
if (DFS(i)) ans++;
}
return ans;
}
int main()
{
int T;
scanf("%d",&T);
while (T--)
{
memset(G,,sizeof(G));
scanf("%d%d",&P,&N);
for (int i=;i<=P;i++)
{
int cp;
scanf("%d",&cp);
for (int j=;j<=cp;j++)
{
int x;
scanf("%d",&x);
G[i][x]=;
}
}
if (Max_match()==P) printf("YES\n");
else printf("NO\n");
}
return ;
}
Courses的更多相关文章
- poj 2239 Selecting Courses (二分匹配)
Selecting Courses Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8316 Accepted: 3687 ...
- POJ 1469 COURSES
COURSES Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20478 Accepted: 8056 Descript ...
- HDOJ 1083 Courses
Hopcroft-Karp算法模板 Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- HDU-----(1083)Courses(最大匹配)
Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- POJ 1469 COURSES(二部图匹配)
COURSES Time Limit: 1000MS Memory ...
- 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 ...
- Windows Kernel Security Training Courses
http://www.codemachine.com/courses.html#kerdbg Windows Kernel Internals for Security Researchers Thi ...
- poj 1469 COURSES(匈牙利算法模板)
http://poj.org/problem?id=1469 COURSES Time Limit: 1000MS Memory Limit: 10000K Total Submissions: ...
- hdoj 1083 Courses【匈牙利算法】
Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
随机推荐
- 背景透明的 Dialog
一:控制Dialog 的背景方法:1.定义一个无背景主题主题 <!--去掉背景Dialog--> <style name="NobackDialog" paren ...
- codeforces 258div2 B Sort the Array
题目链接:http://codeforces.com/contest/451/problem/B 解题报告:给出一个序列,要你判断这个序列能不能通过将其中某个子序列翻转使其成为升序的序列. 我的做法有 ...
- HDU 1029 Ignatius and the Princess IV
解题报告: 题目大意:就是要求输入的N个数里面出现的次数最多的数是哪一个,水题.暴力可过,定义一个一位数组,先用memset函数初始化,然后每次输入一个数就将下标对应的上标对应的那个数加一,最后将整个 ...
- 使用 systemd timer 备份数据库
导读 主要的Linux发行版都改用systemd 来替代 System V启动方式,其中 systemd timer 能替代 crontab 计划任务的大部分功能.本文介绍了用systemd time ...
- Stanford机器学习---第九讲. 聚类
原文:http://blog.csdn.net/abcjennifer/article/details/7914952 本栏目(Machine learning)包括单参数的线性回归.多参数的线性回归 ...
- DCMTK开源库的学习笔记4:利用ini配置文件对dcm影像进行归档
转:http://blog.csdn.net/zssureqh/article/details/8846337 背景介绍: 医学影像PACS工作站的服务端需要对大量的dcm文件进行归档,写入数据库处理 ...
- 暑假热身 A. GCC
GCC编译器是一个由GNU项目维护的编译系统,它支持多种编程语言的编译.但是它并不包含数学运算符“!”.在数学中,这个符号代表阶乘.表达式n!的意思是从1到n的所有整数的乘积. 例如,4!=4*3*2 ...
- 二模Day2题解
小明搬家 题目描述 小明要搬家了,大家都来帮忙. 小明现在住在第N楼,总共K个人要把X个大箱子搬上N楼. 最开始X个箱子都在1楼,但是经过一段混乱的搬运已经乱掉了.最后大家发现这样混乱地搬运过程效率太 ...
- 《ASP.NET1200例》ASP.Net 之Datalist数据删除(支持批量)
.aspx <div> <asp:DataList ID="DataList1" runat="server" Width="355 ...
- iOS category中的所谓属性 和 从xib初始化对象的方法 以及类扩展
今天在编码时遇到以下代码 @interface UITextField (TCCustomFont) @property (nonatomic, copy) NSString* fontName; @ ...