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 ...
随机推荐
- JS中的五种去重方法
JS中的五种去重方法 第一种方法: 第二种方法: 第三种方法: 第四种方法: 第五种方法:优化遍历数组法 思路:获取没重复的最右一值放入新数组 * 方法的实现代码相当酷炫,* 实现思路:获取没重复的 ...
- java整型byte,short,int,long取值范围大小
byte 1个字节 short 2个字节 int 4个字节long 8 个字节 varchar 可变长度的非Unicode数据,最长为8000个字符nvarchar 可变长度Unicode数据,最长 ...
- ubuntu设置PATH
试了好多遍,多无效.. 最后在/etc/enviroment下设置才有效. 不过让有一些未解问题 我使用sudo su 进入到root用户权限,设置完成的. 重新使用sudo -s进入root用户权限 ...
- java ee服务器/应用服务器的理解
42.由Apache.Sun 和其他一些公司及个人共同开发而成.由于有了Sun 的参与和支持,最新的Servlet 和JSP 规范总是能在Tomcat 中得到体现.43.可以这样认为,当在一台机器上配 ...
- POJ3684 Physics Experiment 【物理】
Physics Experiment Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1031 Accepted: 365 ...
- Linux进程的内存布局
这张图很好,注意其中最上面是高位地址,虽然很多个0,但是c开头的,不要看反了: 更具体的可以看这里: A.正文段.这是由cpu执行的机器指令部分.通常,正文段是可共享的,所以即使是经常执行的程序(如文 ...
- adt-bundle-windows加入NDK支持
近期换了个硬盘,曾经都是用eclipse安装adt插件的,如今老了,图省事就下载了adt-bundle-windows,解压缩出来就直接用.但是这个adt-bundle没有集成NDK支持,于是手动安装 ...
- UVALive 4225 / HDU 2964 Prime Bases 贪心
Prime Bases Problem Description Given any integer base b >= 2, it is well known that every positi ...
- node14---分层结构数据库操作
/**回调函数(函数作为参数): 0. 外层函数调用的地方,一定是外层函数体先执行,回调函数和普通函数地址一样,然后看函数体规定回调函数怎么执行. 1. 异步时候使用回调函数, 无论是否异步,回调函数 ...
- ios学习--第三方框架-MBProgressHUD以及扩展
MBProgressHUD提示框官网地址:https://github.com/jdg/MBProgressHUD 一. 模式 首先, MBProgressHUD有以下几种视图模式. typedef ...