Courses

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 5411    Accepted Submission(s): 2597
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
 
Recommend
We have carefully selected several similar problems for you:  1068 2444 1150 1281 1045 

#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;
}

最新文章

  1. php 构造函数格式,具体该怎么写?应该注意什么呢?
  2. Log4j 使用总结
  3. 在PHP中利用wsdl创建标准webservice
  4. Mac上mariadb的启动与关闭
  5. 240多个jQuery插件
  6. ubuntu 快捷键和安装知识知识
  7. zf-关于平台的用户名密码的设置
  8. DeepLearning.ai学习笔记(三)结构化机器学习项目--week2机器学习策略(2)
  9. [HNOI2011]XOR和路径 &amp;&amp; [HNOI2013]游走
  10. phpmyadmin设置编码和字符集gbk或utf8_导入中文乱码解决方法
  11. java里的堆内存于栈内存的区别
  12. mycat+mysql集群:实现读写分离,分库分表
  13. vue-awesome-swiper 水平滚动异常
  14. jokes
  15. 1: unit test
  16. Universal-ImageLoader,Picasso,Fresco,Glide对比
  17. 改写了禁用或启用oracle数据库的约束的存储过程
  18. 内联/块级元素的宽高及margin/padding的说明 |||||| 为何img、input等内联元素可以设置宽、高
  19. vim 可视化模式(visual模式)
  20. mysql 常用语句记录

热门文章

  1. 后端springmvc,前端html5的FormData实现文件断点上传
  2. angular2之组件通讯
  3. jQuery插件的怎么写
  4. 【sqli-labs】 less26 GET- Error based -All you SPACES and COMMENTS belong to us(GET型基于错误的去除了空格和注释的注入)
  5. Mysql 之实现多字段模糊查询
  6. JDK8新特性 -- Function接口: apply,andThen,compose
  7. Java 各级注解及@Autowired注入为null解决办法
  8. 为什么多 TCP 连接比单 TCP 连接传输快
  9. js:重复输出字符串中字符
  10. nyoj51-管闲事的小明