题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2444

题意:有n个学生,m个关系,但是如果a认识b,b认识c,但是a不一定认识c;

求能不能把这n个人分成两个房间,每个房间的人互相都不认识,这就是让我们判断是不是二分图了,可以用涂色法来进行判断;

如果是二分图则求出来最大匹配是多少;

可以把两个房间的人分成两个数组也可以不分让结果除以2就行了

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 210 int maps[N][N], vis[N], used[N], n, ans, p, q;
int color[N];///利用涂色法判断是否为二分图; bool Find(int u)
{
for(int i=; i<=n; i++)
{
int x = i;
if(!vis[x] && maps[u][x])
{
vis[x] = ;
if(!used[x] || Find(used[x]))
{
used[x] = u;
return true;
}
}
}
return false;
} int main()
{
int m;
int x, y, flag;
while(scanf("%d %d", &n, &m)!=EOF)
{
flag = ;
p = q = ;
memset(color, , sizeof(color));
memset(maps, , sizeof(maps));
memset(used, , sizeof(used));
for(int i=; i<=m; i++)
{
scanf("%d%d", &x, &y);
maps[x][y] = maps[y][x] = ;
if(color[x]== && color[y]==)
{
color[x] = ;
color[y] = -;
}
else if(color[x]!= && color[y]==)
color[y] = -color[x];
else if(color[x]== && color[y]!=)
color[x] = -color[y];
else if(color[x]==color[y] && color[x]!=)
flag=;
}
if(flag==)
{
printf("No\n");
continue;
}
int ans = ;
for(int i=; i<=n; i++)
{
memset(vis, , sizeof(vis));
if(Find(i))
ans++;
}
printf("%d\n", ans/);///因为最终会存入1-2和2-1,所以要除以二;
}
return ;
}

The Accomodation of Students---hdu2444(二分图,最大匹配)的更多相关文章

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

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

  2. HDU 2444 The Accomodation of Students【二分图最大匹配问题】

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2444 题意:首先判断所有的人可不可以分成互不认识的两部分.如果可以分成 ,则求两部分最多相互认识的对数. ...

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

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

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

    [题目链接]:pid=2444">click here~~ [题目大意]: 给出N个人和M对关系,表示a和b认识,把N个人分成两组,同组间随意俩人互不认识.若不能分成两组输出No,否则 ...

  5. HDU-2444-The Accomodation of Students(二分图判定,最大匹配)

    链接: https://vjudge.net/problem/HDU-2444#author=634579757 题意: There are a group of students. Some of ...

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

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

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

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

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

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

  9. HUD 2444 The Accomodation of Students (二分图染色+最大匹配)

    #include<iostream> #include<cstdio> #include<cstring> #define maxn 2010 using name ...

  10. HDU 2444:The Accomodation of Students(二分图判定+匹配)

    http://acm.hdu.edu.cn/showproblem.php?pid=2444 题意:给出边,判断这个是否是一个二分图,并求最大匹配. 思路:先染色法求出是否是一个二分图,然后再匈牙利求 ...

随机推荐

  1. 感谢各位亲们的大力支持,免费的HTML5学习课程《HTML5网页开发实例具体解释》连载已经结束了!

    感谢各位亲们的大力支持,免费的HTML5学习课程<HTML5网页开发实例具体解释>连载已经结束了.  有兴趣的读者能够看我的博客,也能够看以下的链接逐个学习: 当里个当.免费的HTML5连 ...

  2. 分配All AD User到SharePoint Group中

    使用名称为“NT AUTHORITY\Authenticated Users”

  3. Http Digest认证协议

    转自:http://blog.csdn.net/htjoy1202/article/details/7067287 其认证的基本框架为挑战认证的结构,如下图所示: 1.客户端希望取到服务器上的某个资源 ...

  4. mongodb group php 操作

    紧接着上篇来,这篇主要讲,mongodb的group功能,做的还是挺强大的,相当对于find(),skip(),distinct()等,用法比较复杂. 测试数据 > db.fruit.find( ...

  5. Spark Streaming源码分析 – Checkpoint

    PersistenceStreaming没有做特别的事情,DStream最终还是以其中的每个RDD作为job进行调度的,所以persistence就以RDD为单位按照原先Spark的方式去做就可以了, ...

  6. C#资源释放及Dispose、Close和析构方法

    https://www.cnblogs.com/luminji/archive/2011/01/05/1926468.html C#资源释放及Dispose.Close和析构方法   备注:此文的部分 ...

  7. easyui-textbox 只读设置取消

    <script> $(function () { $("#txt_beginAmount").attr('readonly', true); $("#txt_ ...

  8. 交换a、b的值temp = a; a = b; b = temp;比a = a^b;b = a^b;a = a^b;快

    先看代码,交换a.b的值十亿次 <span style="font-size:14px;"> int a=222; int b=111; int size = 1000 ...

  9. Redis(七)-- SpringMVC整合Redis集群

    1.pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www ...

  10. mac 获取idea&&datagrip激活码

    mac 版本的修改如下: 1). Command+Shift+G 2). /private/etc/ 3). 找到hosts文件,用文集编辑器打开 4). 输入0.0.0.0 account.jetb ...