HDU-2444 The Accomodation of Students
先用染色法判断是否存在奇数环,也就是方案是否可行。然后二分匹配。
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <fstream>
#include <iostream>#define rep(i, l, r) for(int i=l; i<=r; i++)
#define down(i, l, r) for(int i=l; i>=r; i--)
#define N 234
#define MAX 1<<30using namespace std;
int read()
{int x=0, f=1; char ch=getchar();while (ch<'0' || ch>'9') { if (ch=='-') f=-1; ch=getchar(); }while (ch>='0' && ch<='9') { x=x*10+ch-'0'; ch=getchar(); }return x*f;
}struct node{int y, n;} e[N*N]; int fir[N], en;
int n, m, k[N], c[N], ans;
bool f, b[N];inline void Add(int x, int y)
{en++, e[en].y=y, e[en].n=fir[x], fir[x]=en;en++, e[en].y=x, e[en].n=fir[y], fir[y]=en;
}void Search(int x)
{int o=fir[x], y=e[o].y;while (o){if (c[y]==c[x]) f=true; if (!c[y]) { c[y]=3-c[x]; Search(y); }o=e[o].n, y=e[o].y;}
}bool Find(int x)
{int o=fir[x], y=e[o].y;while (o){if (!b[y]) {b[y]=1; if (!k[y] || Find(k[y])) { k[y]=x; return true; }}o=e[o].n, y=e[o].y;}return false;
}int main()
{while (~scanf("%d%d", &n, &m)){f=false; ans=en=0; rep(i, 1, n) fir[i]=k[i]=c[i]=0;rep(i, 1, m) { int x=read(), y=read(); Add(x, y); }rep(i, 1, n) if (!c[i]) { c[i]=1; Search(i); }if (f) { printf("No\n"); continue; }rep(i, 1, n) if (c[i]==1) {rep(j, 1, n) b[j]=0;if (Find(i)) ans++;}printf("%d\n", ans);}return 0;
}
转载于:https://www.cnblogs.com/NanoApe/p/4342791.html
HDU-2444 The Accomodation of Students相关推荐
- HDU 2444 The Accomodation of Students 二分图匹配
HDU 2444 The Accomodation of Students 二分图匹配 题目来源: HDU 题意: 给出学生数n和关系数m,接下来给出m个关系. 要求将学生分成两部分,每一部分不能有互 ...
- HDU 2444 The Accomodation of Students (二部图+染色)
The Accomodation of Students Time Limit : 5000/1000ms (Java/Other) Memory Limit : 32768/32768K (Ja ...
- 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对人相互认识: 问能否分成两个组,组内任意两个人之间不认识: 若不能,则输出No: 若能,则相互认识的两个人一间房,求最多需要几间房: 给出一些学生的认识情况,比如A和B认 ...
- HDU 2444 The Accomodation of Students
首先是要构造二分图,然后二分图的最大匹配. 还有没完全证明过我的方法的正确性,但是AC了..... #include<cstdio> #include<cstring> #in ...
- HDU - 2444 The Accomodation of Students(二分图判断+二分图最大匹配)
题目链接:点击查看 题目大意:给出n个学生,他们之间有m个认识关系,但认识关系不具有传递性,比如A认识B,B认识C,A不一定认识C,现在给出认识关系,先判断是否能够将所有学生分为两个集合A和B中去,集 ...
- HDU 2444:The Accomodation of Students(二分图判定+匹配)
http://acm.hdu.edu.cn/showproblem.php?pid=2444 题意:给出边,判断这个是否是一个二分图,并求最大匹配. 思路:先染色法求出是否是一个二分图,然后再匈牙利求 ...
- (匹配)The Accomodation of Students --HDU --2444
链接: http://acm.hdu.edu.cn/showproblem.php?pid=2444 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- 【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 ...
- hdu 2444(二分图的判断以及求最大匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2444思路:首先要判断能否构成二分图,用bfs对当前点u染色,对u的邻接点v的颜色进行判断,如果为染色, ...
最新文章
- java+构建+工具+Ant+Maven+Gradle
- python 检测文件或文件夹是否存在
- 通过jsl工具将java程序注册为windows服务
- 动态代理:JDK动态代理和CGLIB代理的区别
- cmake / aux_source_directory
- 模板类的全特化、偏特化
- 前端后台管理系统梳理
- 具有中央异常处理和VO验证的Spring Data JPA –框架
- CachedIntrospectionResults 初始化
- 第三十九期:原生图数据库的15条规则
- linux 驱动基础知识(2)---设备树
- GO语言练习:网络编程 ICMP 示例
- Java Date Time 教程-System.currentTimeMillis()
- fNIRS 公开数据集整理
- 网站域名解析为什么错误?域名解析错误怎么解决?
- 如何查看 Mac ssh key
- 【图像转换】基于matlab灰度图像转换彩色图像【含Matlab 1233期】
- 从燃油车布局新能源,汽车服务商们谋破局
- BI@report钻取操作
- 关于局域网内,超简单实现电脑与Android设备的文件传输。
热门文章
- python教程实例-python教程实例
- 学python需要什么文化基础-和尧名大叔一起从0开始学Python编程-循环
- 学了python可以从事什么岗位-学完Python编程可以从事哪些岗位?
- python3.8.2安装教程-Python3.8.2 软件介绍(附安装包)
- python的优点-python的功能与优缺点
- python处理excel字典-使用Python代码处理Excel
- python编程难吗-都说python很简单 真的很好学么?
- python北京理工大学推荐的书-Python语言程序设计
- java好还是python好-现在学Python还是Java好呢?
- Linux的关机命令和重启命令