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 ...
随机推荐
- BZOJ 3262 陌上花开 (三维偏序CDQ+树状数组)
题目大意: 题面传送门 三维偏序裸题 首先,把三元组关于$a_{i}$排序 然后开始$CDQ$分治,回溯后按$b_{i}$排序 现在要处理左侧对右侧的影响了,显然现在左侧三元组的$a_{i}$都小于等 ...
- vue如何根据返回的值对元素进行样式渲染
1.最终显示样式: 需要:根据任务状态值,显示不同颜色的原点表示任务状态,以及对优先级的数据,进行☆标记 2.代码实现: 在<el-table-column>中需要显示的内容前面,添加图标 ...
- tp框架引入第三方sdk的经验总结
tp框架开发常用到第三方的接口,这时候需要引入第三方的sdk.例如:微信扫码支付sdk,阿里大于的淘宝sdk等等 首先到官网上下载对应php的sdk文件,通常会有至少一个实例代码. 1 新建一个控制器 ...
- dubbo Failed to check the status of the service com.user.service.UserService. No provider available for the service
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'u ...
- Informatica PowerCenter使用介绍-转载
转载自:https://blog.csdn.net/wen_demon/article/details/44155639 1. INFORMATICA CLIENT的使用1.1 Repository ...
- HDU 4325 Contest 3
很明显的区间加减单点查询.但由于规模大,于是离散化.在离散化的时候,可以把要查询的点也加入离散化的数组中. #include <iostream> #include <algorit ...
- [TS] Class Properties Public, Private and Read Only Modifiers
In the constructor, we want to set the prop to readonly, you need to do like this: class Superhero { ...
- Android中的单位
Android中的单位 1.px 像素(pixels) VGA 480*640像素 (Video Graphics Array) QVGA 240*320像素 (Quarter VGA) HVGA 3 ...
- MapReduce运行流程具体解释
在hadoop中.每一个mapreduce任务都会被初始化为一个Job. 每一个Job又能够分为两个阶段:map阶段和reduce阶段.这两个阶段分别用两个函数来表示,即map函数和reduce函数. ...
- 【Oracle学习笔记】
内容主要包括: (1)三种循环及其简化 (2)游标的使用 (3)异常处理 (4)存储过程 (5)存储函数 (6)触发器 (7)其它pl/sql操作 ---------------loop循环定义变量- ...