COURSES
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 21515   Accepted: 8455

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

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 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抣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

Source

——————————————————————————我是分割线——————————————————————————————

二分图最大匹配。

邻接矩阵map[i][j]表示j号喜欢i号课程,然后对课程进行寻找匹配,匹配成功则标记,之后统计匹配数目即可。

这题丧心病狂卡时,我改了两天,最后发现I/O超时了。。。 取消同步后的流还是略微慢一些,用标准输入输出可以正好卡过。TAT

 /*
Problem:
OJ:
User:
Time:
Memory:
Length:
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstdlib>
#include<iomanip>
#include<cassert>
#include<climits>
#include<vector>
#include<list>
#include<map>
#define maxn 1001
#define F(i,j,k) for(int i=j;i<=k;i++)
#define M(a,b) memset(a,b,sizeof(a))
#define FF(i,j,k) for(int i=j;i>=k;i--)
#define inf 0x7fffffff
#define maxm 2016
#define mod 1000000007
//#define LOCAL
using namespace std;
int read(){
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,p;
bool kc[maxn][maxn];
bool vis[maxn];
int pp[maxn];
inline int path(int u)
{
int a,b,temp;
F(i,,n){
if(kc[u][i]&&!vis[i]){
vis[i]=true;
temp=pp[i];
pp[i]=u;
if(temp==-||path(temp)) return ;
pp[i]=temp;
}
}
return ;
}
inline int solve()
{
int a,b,ans=;
M(pp,-);
F(i,,p){
M(vis,);
// ans+=path(i);
if(path(i)) ans++;
if(ans==p) break;
}
return ans;
}
int main()
{
int t;cin>>t;
while(t--){
scanf("%d", &p);scanf("%d", &n);
M(kc,);
int num,cnt;
F(i,,p){
scanf("%d", &num);
F(j,,num){
scanf("%d", &cnt);
kc[i][cnt]=true;
}
}
if(solve()==p) printf("YES\n");
else printf("NO\n");
}
return ;
}

最新文章

  1. rsync密码使用要注意的几个点
  2. HA模式下历史服务器配置
  3. python基础学习二——第二天
  4. Git commit 常见用法
  5. Sublime-text 自己定义快捷键攻略
  6. Flash中用AS3做的游戏,导出apk安装到手机上滤镜效果出不来为什么?
  7. 在MySql中实现MemberShip的权限管理
  8. 解决mac下atom安装插件失败问题
  9. Swift2.2 看完这篇博客 你不想懂也会懂得----二叉树
  10. 解决 Linux error while loading shared libraries: cannot open shared object file: No such file or directory
  11. PageRank_网页排名_MapReduceJava代码实现思路
  12. css学习の第一四弹—代码格式简写归纳
  13. ubuntu数据库安装配置
  14. java学习笔记19(Arrays类)
  15. day4作业(基本运算流程if for)
  16. JavaScript进行简单的随即验证码生成(适合和我一样刚入门一本完整的教材书都没看完的弟弟)
  17. 网站前端优化技术 BigPipe分块处理技术
  18. 安卓程序代写 网上程序代写[原]Android开发技巧--ListView
  19. Java集合技巧
  20. Linux进程管理子系统

热门文章

  1. Xcode的快捷键及代码格式化
  2. vue开发computed,watch,method执行的先后顺序
  3. h5行情k线开发
  4. 虚拟机spark集群搭建
  5. select 1 from dual
  6. [leetcode sort]56. Merge Intervals
  7. python 模式之工厂模式
  8. 学好js,这些js函数概念一定要知道
  9. 面向对象设计原则 开放封闭原则(Open Closed Principle)
  10. PHP 快速排序算法详解