poj 1469 COURSES 题解

时间:2022-09-05 11:28:52
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 ;
}

poj 1469 COURSES 题解的更多相关文章

  1. POJ 1274 The Perfect Stall &vert;&vert; POJ 1469 COURSES(zoj 1140)二分图匹配

    两题二分图匹配的题: 1.一个农民有n头牛和m个畜栏,对于每个畜栏,每头牛有不同喜好,有的想去,有的不想,对于给定的喜好表,你需要求出最大可以满足多少头牛的需求. 2.给你学生数和课程数,以及学生上的 ...

  2. poj 1469 COURSES&lpar;匈牙利算法模板)

    http://poj.org/problem?id=1469 COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions:  ...

  3. POJ 1469 COURSES 二分图最大匹配 二分图

    http://poj.org/problem?id=1469 这道题我绝壁写过但是以前没有mark过二分图最大匹配的代码mark一下. 匈牙利 O(mn) #include<cstdio> ...

  4. poj 1469 COURSES 解题报告

    题目链接:http://poj.org/problem?id=1469 题目意思:有 N 个人,P个课程,每一个课程有一些学生参加(0个.1个或多个参加).问 能否使得 P 个课程 恰好与 P 个学生 ...

  5. POJ 1469 COURSES

    COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20478   Accepted: 8056 Descript ...

  6. POJ 1469 COURSES&lpar;二部图匹配&rpar;

                                                                     COURSES Time Limit: 1000MS   Memory ...

  7. poj 1469 COURSES &lpar;二分匹配&rpar;

    COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16877   Accepted: 6627 Descript ...

  8. POJ - 1469 COURSES (匈牙利算法入门题)

    题意: P门课程,N个学生.给出每门课程的选课学生,求是否可以给每门课程选出一个课代表.课代表必须是选了该课的学生且每个学生只能当一门课程的. 题解: 匈牙利算法的入门题. #include < ...

  9. poj 1469 COURSES &lpar;二分图模板应用 【&ast;模板】 &rpar;

    COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18454   Accepted: 7275 Descript ...

随机推荐

  1. linux命令:目录结构

      可分享的(shareable) 不可分享的(unshareable) 不变的(static) /usr (软件放置处) /etc (配置文件) /opt (第三方协力软件) /boot (开机与核 ...

  2. Java NIO服务器端开发

    一.NIO类库简介 1.缓冲区Buffer Buffer是一个对象,包含一些要写入和读出的数据. 在NIO中,所有的数据都是用缓冲区处理的,读取数据时,它是从通道(Channel)直接读到缓冲区中,在 ...

  3. java 网络编程(二)----UDP基础级的示例

    下面介绍UDP基础级的代码示例: 首先了解创建UDP传输的发送端的思路: 1.创建UDP的Socket服务.2.将要发送的数据封装到数据包中.3.通过UDP的socket服务将数据包发送出去.4.关闭 ...

  4. wuzhicms私密下载链接生成

    加载函数库:load_function('content','content'); echo private_file('http://dev.wuzhicms.com/uploadfile/2014 ...

  5. javascript中通过replace函数搜索和替换指定字符串

    javascript中我们可以通过replace函数替换部分字符串为指定字符串,本文展示了replace的详细用法,并且通过范例演示了如何进行部分替换.完整替换和不区分大小写替换. javascrip ...

  6. 规范javascript书写

    空白 缩进 换行限制 if while for do 2.  命名 常量 URL_CONFIG 变量 listLen 函数命名 调用函数  function setStyle(dom, name, v ...

  7. Solr4&period;8&period;0源码分析&lpar;13&rpar;之LuceneCore的索引修复

    Solr4.8.0源码分析(13)之LuceneCore的索引修复 题记:今天在公司研究elasticsearch,突然看到一篇博客说elasticsearch具有索引修复功能,顿感好奇,于是点进去看 ...

  8. JNDI--Java命名和目录接口

    JNDI主要用于在容器中配置某些资源,让所有项目可以使用.JNDI可以提供: 1:数据库连接池.            自定义连接池             第三方连接池 Dbcp           ...

  9. ssh登录错误ECDSA host key for ip has changed解决方案

    当我们使用ssh root@ip登录Linux服务器时,服务器报错: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WAR ...

  10. hyperledger fabric部署总结

    之前在有道云笔记上分享过,但想想还是搬到这里来吧,以后统一方便整理自己的知识进入正题.... 之前在调研 hyperledger fabric,其实部署说明官网都有,只是东西都是国外的照着操作也会遇到 ...