HUD 2444 The Accomodation of Students (二分图染色+最大匹配)
#include<iostream>
#include<cstdio>
#include<cstring>
#define maxn 2010
using namespace std;
int n,m,num,head[maxn],f[maxn],match[maxn],color[maxn];
struct node
{
int u,v,pre;
}e[maxn*maxn];
void Add(int from,int to)
{
num++;
e[num].u=from;
e[num].v=to;
e[num].pre=head[from];
head[from]=num;
}
bool Color(int s)
{
for(int i=head[s];i;i=e[i].pre)
if(!color[e[i].v])
{
color[e[i].v]=-*color[s];
if(!Color(e[i].v))return ;
}
else if(color[e[i].v]==color[s])return ;
return ;
}
int Dfs(int s)
{
for(int i=head[s];i;i=e[i].pre)
if(f[e[i].v]==)
{
f[e[i].v]=;
if(match[e[i].v]==||Dfs(match[e[i].v]))//XXXXX又是这句错了 下次再写错就XXXX
{
match[e[i].v]=s;
return ;
}
}
return ;
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
num=;
memset(f,,sizeof(f));
memset(head,,sizeof(head));
memset(color,,sizeof(color));
memset(match,,sizeof(match));
int u,v;
for(int i=;i<=m;i++)
{
scanf("%d%d",&u,&v);
Add(u,v);Add(v,u);
}
if(n==)
{
printf("No\n");
continue;
}
color[]=;
if(!Color())
{
printf("No\n");
continue;
}
int ans=;
for(int i=;i<=n;i++)
{
memset(f,,sizeof(f));
ans+=Dfs(i);
}
printf("%d\n",ans/);
}
return ;
}
HUD 2444 The Accomodation of Students (二分图染色+最大匹配)的更多相关文章
- HDU 2444 The Accomodation of Students 二分图判定+最大匹配
题目来源:HDU 2444 The Accomodation of Students 题意:n个人能否够分成2组 每组的人不能相互认识 就是二分图判定 能够分成2组 每组选一个2个人认识能够去一个双人 ...
- HDU2444 :The Accomodation of Students(二分图染色+二分图匹配)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- HDU 2444 - The Accomodation of Students - [二分图判断][匈牙利算法模板]
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2444 Time Limit: 5000/1000 MS (Java/Others) Mem ...
- HDU 2444 The Accomodation of Students (二分图存在的判定以及最大匹配数)
There are a group of students. Some of them may know each other, while others don't. For example, A ...
- HDU 2444 The Accomodation of Students二分图判定和匈牙利算法
本题就是先推断能否够组成二分图,然后用匈牙利算法求出最大匹配. 究竟怎样学习一种新算法呢? 我也不知道什么方法是最佳的了,由于看书本和大牛们写的匈牙利算法具体分析,看了几乎相同两个小时没看懂,最后自己 ...
- hdu 2444 The Accomodation of Students(最大匹配 + 二分图判断)
http://acm.hdu.edu.cn/showproblem.php?pid=2444 The Accomodation of Students Time Limit:1000MS Me ...
- hdu_2444The Accomodation of Students(二分图的判定和计算)
hdu_2444The Accomodation of Students(二分图的判定和计算) 标签:二分图匹配 题目链接 题意: 问学生是否能分成两部分,每一部分的人都不相认识,如果能分成的话,两两 ...
- hdu 2444 The Accomodation of Students 判断二分图+二分匹配
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- HDU 2444 The Accomodation of Students(二分图判定+最大匹配)
这是一个基础的二分图,题意比较好理解,给出n个人,其中有m对互不了解的人,先让我们判断能不能把这n对分成两部分,这就用到的二分图的判断方法了,二分图是没有由奇数条边构成环的图,这里用bfs染色法就可以 ...
随机推荐
- sql语句中出现笛卡尔乘积
没有join条件导致笛卡尔乘积 学过线性代数的人都知道,笛卡尔乘积通俗的说,就是两个集合中的每一个成员,都与对方集合中的任意一个成员有关联.可以想象,在SQL查询中,如果对两张表join查询而没有jo ...
- Oracle数据库基础知识_字符串操作相关2
6.LPAD,RPAD 作用:左/右边的字符串填充一些特定的字符语法: LPAD(string , n, [pad_String]) string:可是字符或者参数 ...
- Xcode 5 解决 The operation couldn’t be completed. (NSURLErrorDomain error -1012.) 问题
使用Xcode6.1 SVN 出现问题 The operation couldn’t be completed. (NSURLErrorDomain error -1012.) 解决方法: 打开终端 ...
- 图片的css自适应
当需要css来缩放图片的时候,可以采用外层容器100%或者任意百分比, 内层图片img tag 没有宽高,用sass写经过断点后的mixin中的样式就是这样: .workscon_section{ w ...
- Content related to smartcards (and RFID/NFC)
Introduction Add your content here. ISO/IEC 7816 Contact Cards Hardware EMV payment cards Orange Cas ...
- c#:类 相关练习;
1. 2. int i = a.Length;//获取字符串的长度 a = a.ToLower();//将字符串中的大写英文字符转化为小写 a = a.ToUpper();//将字符串中的小写 ...
- Maven实战一
转载:http://www.iteye.com/topic/1123221 1. 用Maven 命令创建一个简单的Maven项目 在cmd中运行如下命令: Cmd代码 mvn archetype:ge ...
- struts2接收参数——域模型、DTO
在开始介绍域模型之前我们要明白一点,为什么通过域模型我们可以把参数这么方便的在后台接收. 那是因为 通过参数拦截器(params interceptor)自动的把前台传过来的参数给域对象(domain ...
- Inotify: 高效、实时的Linux文件系统事件监控框架
Inotify: 高效.实时的Linux文件系统事件监控框架 概要 - 为什么需要监控文件系统? 在日常工作中,人们往往需要知道在某些文件(夹)上都有那些变化,比如: 通知配置文件的改变 ...
- Blue Jeans(串)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10083 Accepted: 4262 Description The ...