POJ——T 1469 COURSES
http://poj.org/problem?id=1469
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 24197 | Accepted: 9428 |
Description
- 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
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
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
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector> using namespace std; const int N();
int p,n,ans,match[N];
vector<int>vec[N];
bool vis[N]; bool DFS(int now)
{
for(int v,i=;i<vec[now].size();i++)
{
v=vec[now][i];
if(vis[v]) continue;
vis[v]=;
if(!match[v]||DFS(match[v]))
{
match[v]=now;
return true;
}
}
return false;
} int AC()
{
int t; scanf("%d",&t);
for(;t--;ans=)
{
for(int i=;i<=N;i++) vec[i].clear();
memset(match,,sizeof(match));
scanf("%d%d",&p,&n);
for(int q,v,u=;u<=p;u++)
{
for(scanf("%d",&q);q--;)
scanf("%d",&v),vec[u].push_back(v+p);
}
for(int i=;i<=p;i++)
{
memset(vis,,sizeof(vis));
if(DFS(i)) ans++;
}
if(ans==p) puts("YES");
else puts("NO");
}
return ;
} int I_want_AC=AC();
int main(){;}
vector实现
#include <algorithm>
#include <cstring>
#include <cstdio> using namespace std; const int N();
int match[N],head[N];
int p,n,ans,sumedge;
struct Edge
{
int v,next;
Edge(int v=,int next=):v(v),next(next){}
}edge[N];
inline void ins(int u,int v)
{
edge[++sumedge]=Edge(v,head[u]);
head[u]=sumedge;
}
bool vis[N]; bool DFS(int now)
{
for(int v,i=head[now];i;i=edge[i].next)
{
v=edge[i].v;
if(vis[v]) continue;
vis[v]=;
if(!match[v]||DFS(match[v]))
{
match[v]=now;
return true;
}
}
return false;
} int AC()
{
int t; scanf("%d",&t);
for(;t--;sumedge=ans=)
{
scanf("%d%d",&p,&n);
for(int q,v,u=;u<=p;u++)
{
for(scanf("%d",&q);q--;)
scanf("%d",&v),ins(u,v+p);
}
for(int i=;i<=p;i++)
{
memset(vis,,sizeof(vis));
if(DFS(i)) ans++;
}
if(ans==p) puts("YES");
else puts("NO");
memset(edge,,sizeof(edge));
memset(head,,sizeof(head));
memset(match,,sizeof(match));
}
return ;
} int I_want_AC=AC();
int main(){;}
人工 邻接表实现
POJ——T 1469 COURSES的更多相关文章
- poj 1469 COURSES(匈牙利算法模板)
http://poj.org/problem?id=1469 COURSES Time Limit: 1000MS Memory Limit: 10000K Total Submissions: ...
- POJ 1274 The Perfect Stall || POJ 1469 COURSES(zoj 1140)二分图匹配
两题二分图匹配的题: 1.一个农民有n头牛和m个畜栏,对于每个畜栏,每头牛有不同喜好,有的想去,有的不想,对于给定的喜好表,你需要求出最大可以满足多少头牛的需求. 2.给你学生数和课程数,以及学生上的 ...
- poj——2239 Selecting Courses
poj——2239 Selecting Courses Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10656 A ...
- POJ 1469 COURSES 二分图最大匹配 二分图
http://poj.org/problem?id=1469 这道题我绝壁写过但是以前没有mark过二分图最大匹配的代码mark一下. 匈牙利 O(mn) #include<cstdio> ...
- poj 1469 COURSES 解题报告
题目链接:http://poj.org/problem?id=1469 题目意思:有 N 个人,P个课程,每一个课程有一些学生参加(0个.1个或多个参加).问 能否使得 P 个课程 恰好与 P 个学生 ...
- POJ 1469 COURSES
COURSES Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20478 Accepted: 8056 Descript ...
- POJ 1469 COURSES(二部图匹配)
COURSES Time Limit: 1000MS Memory ...
- poj 1469 COURSES 题解
COURSES Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21515 Accepted: 8455 Descript ...
- poj 1469 COURSES (二分匹配)
COURSES Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16877 Accepted: 6627 Descript ...
随机推荐
- dataTable 动态列 二次加载
需要把 列头和表格内容全部清空 if ($('#datatable').hasClass('dataTable')) { var dttable = $('#datatable').dataTable ...
- Git 合并流程
首先把自己的代码提交到自己的分支 再把master[主分支]的代码拉下来更新 解决冲突 推送至自己的分支 请求合并到master[主分支]
- JS[获取两个日期中所有的月份]
//------[获取两个日期中所有的月份中] function getMonthBetween(start,end){ var result = []; var s = start.split(&q ...
- IE9以下版本兼容h5标签
随着html5(后面用h5代表)标签越来越广泛的使用,IE9以下(IE6-IE8)不识别h5标签的问题让人很是烦恼. 在火狐和chrome之类的浏览器中,遇到不认识的标签,只要给个display:bl ...
- HDU 4321 Contest 3
题意:给定a和b,n,让你求b+a, b+2*a, .......b+n*a里面有多少1. 当统计第K位的时候 可以注意到 第 B+T*A 和 B+(T+2^(K+1))*A 位是相同的 那么 第K位 ...
- 暑假NOIP期末考试【1】—— Phantom
Phantom •题目名称: phantom •时间限制:1 秒 •空间限制:256 MiB 题目描写叙述 在一个无限大的棋盘上.排列着 n * n 枚棋子,形成一个 n 行 n 列的方阵.棋子能够横 ...
- struct和typedef
struct Test { int i; }; 解析:此处声明一个Test的结构体. 使用:在C语言中:struct Test t(此处的struct不可省略),在C++中:Test t(能够省略st ...
- IOS假设将一个十六进制的color转换成UIColor,非常有用
UI给开发的效果图非常多时候标注着十六进制的Color,而程序中用到的往往是UIColor能够用例如以下方法去转换: (UIColor *)RGBColorFromHexString:(NSStrin ...
- 零基础学python-5.2 数字表达式操作符
表达式是处理数字最主要的工具 a=1#常量 a=a+1#表达式 操作符 操作符 描写叙述 yield 生成 器函数发送协议 lambda args:expression 生成匿名函数 x if y e ...
- atitit。流程图的设计与制作 attilax 总结
atitit.流程图的设计与制作 attilax 总结 1. 流程图的规范1 2. 画图语言2 2.1. atitit.CSDN-markdown编辑器2 2.2. js-sequence-diagr ...