要先判断是不是二分图。用黑白染色法。

遇到已经染过的跟当前的颜色相同时就说明不是二分图,也即出现了奇环

 /*--------------------------------------------------------------------------------------*/

 #include <algorithm>
#include <iostream>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map> //debug function for a N*M array
#define debug_map(N,M,G) printf("\n");for(int i=0;i<(N);i++)\
{for(int j=;j<(M);j++){\
printf("%d",G[i][j]);}printf("\n");}
//debug function for int,float,double,etc.
#define debug_var(X) cout<<#X"="<<X<<endl;
#define LL long long
const int INF = 0x3f3f3f3f;
const LL LLINF = 0x3f3f3f3f3f3f3f3f;
/*--------------------------------------------------------------------------------------*/
using namespace std; int N,M,T; const int maxn = ;
const int maxm = ;
struct Edge{
int to,next;
}edge[maxm]; int head[maxn],tot;
void init()
{
tot = ;
memset(head,-,sizeof head);
}
void add_edge(int u,int v)
{
edge[tot].to = v;edge[tot].next = head[u];
head[u] = tot++;
} int linker[maxn];
bool used[maxn];
int uN; bool dfs(int u)
{
for(int i=head[u];~i;i=edge[i].next)
{
int v = edge[i].to;
if(!used[v])
{
used[v] = true;
if(linker[v] == - || dfs(linker[v]))
{
linker[v] = u;
return true;
}
}
}
return false;
}
int hungary()
{
int res = ;
memset(linker,-,sizeof linker);
for(int u=;u<=uN;u++)
{
memset(used,false,sizeof used);
if(dfs(u)) res++;
}
return res/;
} int col[maxn];
bool isBipartite(int u)
{
queue<int> Q;
Q.push(u);
col[u] = ;
while(!Q.empty())
{
int cur = Q.front();Q.pop();
for(int i = head[cur];~i;i=edge[i].next)
{
int v = edge[i].to;
if(col[v] == col[cur]) return false;
if(col[v] != -) continue;
col[v] = !col[cur];
Q.push(v);
}
}
return true;
} int main()
{
while(~scanf("%d%d",&N,&M))
{
init();
uN = N;
for(int i=,u,v;i<M;i++)
{
scanf("%d%d",&u,&v);
add_edge(u,v);
add_edge(v,u);
} bool flag = true;
memset(col,-,sizeof col);
for(int i=;i<=uN;i++) if(col[i] == -)
{
if(!isBipartite(i) ){flag = false;break;}
}
if(flag)
{
printf("%d\n",hungary());
}
else printf("No\n"); }
}

HDU2444-The Accomodation of Students-判断是否为二分图+ISAP的更多相关文章

  1. hdu 2444 The Accomodation of Students 判断是否构成二分图 + 最大匹配

    此题就是求最大匹配.不过需要判断是否构成二分图.判断的方法是人选一点标记为红色(0),与它相邻的点标记为黑色(1),产生矛盾就无法构成二分图.声明一个vis[],初始化为-1.通过深搜,相邻的点不满足 ...

  2. HDU2444 The Accomodation of Students —— 二分图最大匹配

    题目链接:https://vjudge.net/problem/HDU-2444 The Accomodation of Students Time Limit: 5000/1000 MS (Java ...

  3. HDU2444 The Accomodation of Students

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

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

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

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

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

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

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

  7. HDU2444 The Accomodation of Students【匈牙利算法】

    题意: 有n个学生,有m对人是认识的,每一对认识的人能分到一间房,问能否把n个学生分成两部分,每部分内的学生互不认识,而两部分之间的学生认识.如果可以分成两部分,就算出房间最多需要多少间,否则就输出N ...

  8. HDU——2444The Accomodation of Students(BFS判二分图+最大匹配裸题)

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

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

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2444 Problem Description There are a group of s ...

  10. HDU2444 The Accomodation of Students(二分图最大匹配)

    有n个关系,他们之间某些人相互认识.这样的人有m对.你需要把人分成2组,使得每组人内部之间是相互不认识的.如果可以,就可以安排他们住宿了.安排住宿时,住在一个房间的两个人应该相互认识.最多的能有多少个 ...

随机推荐

  1. My97DatePicker时间控件使用

    刚刚工作中遇到一个修改时间空间的bug,顺带学习了My97DatePicker时间空间 网上查到的资料已经很详细: http://www.360doc.com/content/14/0606/11/1 ...

  2. github代码上传之命令提交

    Git GUI的用法比较简单,随便弄弄就可以将本地git库中的代码提交到远端github服务器,所以想把Git bash这玩意儿的操作流程快速过一遍,主要是做个笔记,以后忘记了可以看看怎么操作的. 首 ...

  3. Redis客户端开发包:Jedis学习-入门

    添加Jedis依赖 我们可以使用以下三种方式来添加Jedis依赖. 1.下载jar文件 从http://search.maven.org/下载最近的jedis包和Apache Commons Pool ...

  4. MVC 多语言记录1 设置默认的ResourceType

    http://stackoverflow.com/questions/3260748/default-resource-for-data-annotations-in-asp-net-mvc Add ...

  5. webconfig 文件加密处理

    前几日正好遇到配置文件加密解密的问题,简单记录下流程. 1.首先运行cmd然后打开Framework.cd C:\Windows\Microsoft.NET\Framework\v4.0.303192 ...

  6. 记录Sqlserver2012附加Sqlserver2008的数据库出错的解决方案

    一.摘要 最近在实验里面用台式编写好了一个软件,想移植到家里的笔记本上.在附加数据的时候却出现了错误,具体也没有提示什么错误,反正就是附加失败了. 二.解决方案 在网上看了一些资料,有的说[低版本不能 ...

  7. get_free_page

    /**  0.11用了 unsigned char */static unsigned short mem_map [ PAGING_PAGES ] = {0,}; /* * Get physical ...

  8. node命令

  9. poj 2104 K-th Number(可持久线段树)

    K-th Number 持久化:http://www.cnblogs.com/tedzhao/archive/2008/11/12/1332112.html 结构:http://www.docin.c ...

  10. Spring MVC @ResponseBody返回中文字符串乱码问题

    朋友做小项目练手的时候遇到的,着实让他郁闷够呛..这个问题的确很恶心.. 项目中引用的json包,直接用@ResponseBody注解返回json字符串..有关这个的乱码问题网上很多,各种花样各种转码 ...