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 2141 排队 (三维偏序CDQ+树状数组)
题目大意:略 洛谷传送门 和 [CQOI2015]动态逆序对 这道题一样的思路 一开始的序列视为$n$次插入操作 把每次交换操作看成四次操作,删除$x$,删除$y$,加入$x$,加入$y$ 把每次操作 ...
- Map的四种遍历方法
1.取值遍历 for(String key:map.keySet()){ System.out.println("key="+key+"and value=" ...
- 小学生都能学会的python(函数的进阶)
小学生都能学会的python(函数的进阶) 1. 动态传参 形参: 1. 位置参数 2. 默认值参数 3. 动态传参 *args 动态接收位置参数 **kwargs 动态接收关键字参数 def fun ...
- VS2015 C# 编写USB通信上位机时,改变net框架导致DLL调用失败的问题解决方法
最近在写USB通信的上位机,调用了windows里的DLL,开发环境:64位WIN7 .VS2015.NET4.5.2:开发完成后在自己的电脑可用,在32位电脑.NET其他版本以及WIN10的环境下不 ...
- visual studio 2017 使用码云gitee进行源代码管理
在码云新建项目 复制项目地址 visual studio 操作 新建项目 提交到码云
- ACdream 1157 Segments
Segments Time Limit: 2000ms Memory Limit: 10000KB This problem will be judged on ACdream. Original I ...
- (转)Epoll模型详解
1. 内核中提高I/O性能的新方法epoll epoll是什么?按照man手册的说法:是为处理大批量句柄而作了改进的poll.要使用epoll只需要这三个系统调 用:epoll_create(2), ...
- Winserver服务器-AD字段对照简图
AD字段对照简图
- Android 开发之集成百度地图的定位与地图展示
app 应用中,大多数应用都具有定位功能,百度定位就成了开发人员的集成定位功能的首选,近期也在做定位功能,可是发现百度真是个大坑啊, sdk 命名更新了,相关代码却不更新,害得我花费了非常长时间来研究 ...
- 【大话QT之十】实现FTP断点续传
应用需求: 网盘开发工作逐步进入各部分的整合阶段,当用户在client改动或新添加一个文件时.该文件要同步上传到server端相应的用户文件夹下,因此针对传输数据(即:上传.下载)这一块如今既定了三种 ...