#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 (二分图染色+最大匹配)的更多相关文章

  1. HDU 2444 The Accomodation of Students 二分图判定+最大匹配

    题目来源:HDU 2444 The Accomodation of Students 题意:n个人能否够分成2组 每组的人不能相互认识 就是二分图判定 能够分成2组 每组选一个2个人认识能够去一个双人 ...

  2. HDU2444 :The Accomodation of Students(二分图染色+二分图匹配)

    The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  3. HDU 2444 - The Accomodation of Students - [二分图判断][匈牙利算法模板]

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2444 Time Limit: 5000/1000 MS (Java/Others) Mem ...

  4. 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 ...

  5. HDU 2444 The Accomodation of Students二分图判定和匈牙利算法

    本题就是先推断能否够组成二分图,然后用匈牙利算法求出最大匹配. 究竟怎样学习一种新算法呢? 我也不知道什么方法是最佳的了,由于看书本和大牛们写的匈牙利算法具体分析,看了几乎相同两个小时没看懂,最后自己 ...

  6. hdu 2444 The Accomodation of Students(最大匹配 + 二分图判断)

    http://acm.hdu.edu.cn/showproblem.php?pid=2444 The Accomodation of Students Time Limit:1000MS     Me ...

  7. hdu_2444The Accomodation of Students(二分图的判定和计算)

    hdu_2444The Accomodation of Students(二分图的判定和计算) 标签:二分图匹配 题目链接 题意: 问学生是否能分成两部分,每一部分的人都不相认识,如果能分成的话,两两 ...

  8. hdu 2444 The Accomodation of Students 判断二分图+二分匹配

    The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  9. HDU 2444 The Accomodation of Students(二分图判定+最大匹配)

    这是一个基础的二分图,题意比较好理解,给出n个人,其中有m对互不了解的人,先让我们判断能不能把这n对分成两部分,这就用到的二分图的判断方法了,二分图是没有由奇数条边构成环的图,这里用bfs染色法就可以 ...

随机推荐

  1. UIView设置背景渐变色

    UIView设置背景渐变色 // Allocate bitmap context CGContextRef bitmapContext = CGBitmapContextCreate(NULL, , ...

  2. 将数据库字段从float修改为decimal

    decimal(6,2) 可以表示0000.00~9999.99 alter table test modify aaa decimal(6,2); 则表里所有大于10000的数会被设置为9999.9 ...

  3. 专家解读Linux操作系统内核中的GCC特性

    专家解读Linux操作系统内核中的GCC特性   Linux内核使用GNU Compiler Collection (GCC)套件的几个特殊功能.这些功能包括提供快捷方式和简化以及向编译器提供优化提示 ...

  4. BZOJ 1015 星球大战

    Description 很久以前,在一个遥远的星系,一个黑暗的帝国靠着它的超级武器统治者整个星系.某一天,凭着一个偶然的机遇,一支反抗军摧毁了帝国的超级武器,并攻下了星系中几乎所有的星球.这些星球通过 ...

  5. 整理的Java资源

    这里搜集了用来构建应用程序的工具. Apache Maven:Maven使用声明进行构建并进行依赖管理,偏向于使用约定而不是配置进行构建.Maven优于Apache Ant.后者采用了一种过程化的方式 ...

  6. Unity3D 3D横版跑酷

    Unity3d  3D横版跑酷系列(Character Controller组件) @广州小龙 目前在做一个3D跑酷的横版游戏,目前说一下 Character Controller组件! 1.Slop ...

  7. DB2中的系统表SYSIBM.SYSDUMMY1

    ORACLE中有一张系统数据库表DUAL用来访问系统的相关信息 SELECT SYSDATE FROM DUAL;  --返回当前系统日期 ------------------------------ ...

  8. Oracle索引扫描算法

    SQL> create table t as select * from dba_objects; Table created. SQL> create index idx_t on t( ...

  9. sed删除文本第一个匹配行

    源文本如下,要求删除第一个为happy-123456的行. ----------------------------- aaaaaaa happy- bbbbbb asdasawe happy- ds ...

  10. 【转】NDK编译可执行文件在Android L中运行显示error: only position independent executables (PIE) are supported.失败问题解决办法。

    原文网址:http://blog.csdn.net/hxdanya/article/details/39371759 由于使用了NDK编译的可执行文件在应用中调用,在4.4及之前的版本上一直没出问题. ...