hdu 2444 The Accomodation of Students(最大匹配 + 二分图判断)
http://acm.hdu.edu.cn/showproblem.php?pid=2444
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Now you are given all pairs of students who know each other. Your task is to divide the students into two groups so that any two students in the same group don't know each other.If this goal can be achieved, then arrange them into double rooms. Remember, only paris appearing in the previous given set can live in the same room, which means only known students can live in the same room.
Calculate the maximum number of pairs that can be arranged into these double rooms.
Input
Proceed to the end of file.
Output
Sample Input
1 2
1 3
1 4
2 3
6 5
1 2
1 3
1 4
2 5
3 6
Sample Output
3
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#define N 210 int G[N][N], vis[N], used[N];
int m, n, f, c[N]; bool Find(int u)
{
int i;
for(i = ; i <= n ; i++)
{
if(!vis[i] && G[u][i])
{
vis[i] = ;
if(!used[i] || Find(used[i]))
{
used[i] = u;
return true;
}
}
}
return false;
} void DFS(int x, int color)
{
int i;
for(i = ; i <= n ; i++)
{
if(G[x][i])
{
if(c[i] == )
{
c[i] = -color;//将x相邻的点i染成与其不同的颜色
DFS(i, -color);
}
else if(c[i] == color)//如果相邻两点颜色相同则不是二分图
{
f = ;
return ;
}
}
}
} int main()
{
int i, a, b;
while(~scanf("%d%d", &n, &m))
{
memset(G, , sizeof(G));
memset(c, , sizeof(c));
f = ;
while(m--)
{
scanf("%d%d", &a, &b);
G[a][b] = G[b][a] = ;
}
c[] = ;
DFS(, );//将1号染成黑色
if(f == )
printf("No\n");
else
{
int ans = ;
memset(used, , sizeof(used));
for(i = ; i<= n ; i++)
{
memset(vis, , sizeof(vis));
if(Find(i))
ans++;
}
printf("%d\n", ans / );
}
}
return ;
}
hdu 2444 The Accomodation of Students(最大匹配 + 二分图判断)的更多相关文章
- HDU 2444 The Accomodation of Students【二分图最大匹配问题】
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2444 题意:首先判断所有的人可不可以分成互不认识的两部分.如果可以分成 ,则求两部分最多相互认识的对数. ...
- HDU 2444 The Accomodation of Students (二分图最大匹配+二分图染色)
[题目链接]:pid=2444">click here~~ [题目大意]: 给出N个人和M对关系,表示a和b认识,把N个人分成两组,同组间随意俩人互不认识.若不能分成两组输出No,否则 ...
- HDU 2444 The Accomodation of Students(二分图判定+最大匹配)
这是一个基础的二分图,题意比较好理解,给出n个人,其中有m对互不了解的人,先让我们判断能不能把这n对分成两部分,这就用到的二分图的判断方法了,二分图是没有由奇数条边构成环的图,这里用bfs染色法就可以 ...
- 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 题意:n个人能否够分成2组 每组的人不能相互认识 就是二分图判定 能够分成2组 每组选一个2个人认识能够去一个双人 ...
- 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 (判断二分图,最大匹配)
The Accomodation of StudentsTime Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- 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(二分匹配 匈牙利算法 邻接表实现)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
随机推荐
- Jquery源码中的Javascript基础知识(四)— jQuery.fn.init方法
$() 即调用了jQuery.fn.init方法 jQuery = function( selector, context ) { return new jQuery.fn.init( selecto ...
- BZOJ 4415 发牌
线段树就好了啊. 为什么一眼splay啊... 其实splay也能过,但是线段树更方便? #include<iostream> #include<cstdio> #includ ...
- WWDC 2015 - 概记
WWDC 2015已经过去快一个月了,今年似乎没有像去年那样变化巨大,一切都在慢慢演进,iOS.Mac OS.watchOS都变得越来越好. 新的三大平台的发布,iOS 9/Mac OS EL Cap ...
- 使用phantomjs生成网站快照
http://phantomjs.org/ 昨天(2013/08/12)在代码区看到一个生成站点快照的代码,看了半天才发现,作者仅仅贴出来业务代码,最核心的生成快照图片的代码反而没有给出来. 以前记得 ...
- Java RunTime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. ......
mkdir jre cd jre ln -s 你的JDK目录/bin bin 例如:ln -s /usr/lib/jvm/jdk1.8.0_25/bin bin 原文地址:http://www.cnb ...
- sqlplus常用命令
原文 sqlplus常用命令 desc 表名 显示表的结构 show user 显示当前连接用户 show error 显示错误 sho ...
- PHP实现的Mysql读写分离
本代码是从uchome的代码修改的,是因为要解决uchome的效率而处理的.这个思维其实很久就有了,只是一直没有去做,相信也有人有同样的想法,如果有类似的,那真的希望提出相关的建议.封装的方式比较简单 ...
- C++读取二进制文件(某特定格式)
该格式也不复杂,就是一个二进制文件,格式为:8个通道,每个通道2字节,都为整数,最后两个通道都是0x03FF == 1023d,文件中中若干个8通道. 有个小细节就是:下面代码中 infile.rea ...
- java 多线程同步
一.synchronized关键字 同步方法 每个对象都包含一把锁(也叫做监视器),它自动称为对象的一部分(不必为此写任何特殊的代码).调用任何synchronized方法时,对象就会被锁定,不可再调 ...
- java-web查询系统
1:select标签.选择列表~ 让从数据库得到的科目名称全部放入一个ArrayList里,用for循环将其遍历.数据库存取暂不介绍. 效果图: classC班没有此分数段,所以我改成classA p ...