The Accomodation of Students HDU - 2444 二分图判定 + 二分图最大匹配 即二分图-安排房间
/*655.二分图-安排房间 (10分)
C时间限制:3000 毫秒 | C内存限制:3000 Kb
题目内容:
有一群学生,他们之间有的认识有的不认识。
现在要求把学生分成2组,其中同一个组的人相互不认识。如果你分成功了,那么就安排双人间,安排的规矩
是两个人分别属于不同的组,并且认识。
输入描述
首先输入两个整数n,m,表示有n个学生, m个认识对
随后m行表示认识的学生对。
输出描述
如果不能分组成功则输出“No”
否则输出有多少个房间安排学生配对。
输入样例
4 4
1 2
1 3
1 4
2 3
6 5
1 2
1 3
1 4
2 5
3 6
输出样例
No
3
*/
#include<iostream>
#include<stdio.h>
#include<queue>
#include<vector>
#include<string.h>
using namespace std;
const int maxn = ;
int n,m,color[maxn];
vector<int>G[maxn];
int match[maxn];
bool used[maxn];
void addedge(int a,int b){
G[a].push_back(b);
G[b].push_back(a);
} bool dfs(int v){
used[v] = ;
for(int i=;i<G[v].size();i++){
int u = G[v][i],w = match[u];
if(w<||!used[w]&&dfs(w)){
match[v] = u;
match[u] = v;
return ;
}
}
return ;
}
int matching(int n){
int res = ;
memset(match,-,sizeof(match));
for(int v = ;v<=n;v++){
if(match[v]<){
memset(used,,sizeof(used));
if(dfs(v)) res++;
}
}
return res;
} bool is(){
queue<int>q;
memset(color,,sizeof(color));
q.push();
color[] = ;
while(!q.empty()){
int p=q.front();
q.pop();
for(int i=;i<G[p].size();i++){
if(color[G[p][i]]==color[p])
return ;
else{
if(!color[G[p][i]]){
color[G[p][i]] = -color[p];
q.push(G[p][i]);
}
}
}
}
return ;
}
int main(){
while(cin>>n>>m){
int a,b;
for(int i=;i<m;i++){
scanf("%d%d",&a,&b);
addedge(a,b);
}
if(!is()||n==) cout<<"No"<<endl;
else{
cout<<matching(n)<<endl;
}
for(int i=;i<maxn;i++)
G[i].clear();
}
return ;
}
The Accomodation of Students HDU - 2444 二分图判定 + 二分图最大匹配 即二分图-安排房间的更多相关文章
- The Accomodation of Students HDU - 2444(判断二分图 + 二分匹配)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- (匹配)The Accomodation of Students --HDU --2444
链接: http://acm.hdu.edu.cn/showproblem.php?pid=2444 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- B - The Accomodation of Students - hdu 2444(最大匹配)
题意:现在有一些学生给你一下朋友关系(不遵守朋友的朋友也是朋友),先确认能不能把这些人分成两组(组内的人要相互不认识),不能分的话输出No(小写的‘o’ - -,写成了大写的WA一次),能分的话,在求 ...
- HDU-2444-The Accomodation of Students(二分图判定,最大匹配)
链接: https://vjudge.net/problem/HDU-2444#author=634579757 题意: There are a group of students. Some of ...
- HDU2444(KB10-B 二分图判定+最大匹配)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- [hdu4598]二分图判定,差分约束
题意: 给一个图,问能否给每个点分配一个实数值,使得存在一个数实数T,所有点满足:|value(i)| < T 且 u,v之间有边<=> |value(u)-value(v)| &g ...
- HDU 2444 The Accomodation of Students 二分图判定+最大匹配
题目来源:HDU 2444 The Accomodation of Students 题意:n个人能否够分成2组 每组的人不能相互认识 就是二分图判定 能够分成2组 每组选一个2个人认识能够去一个双人 ...
- hdu 2444 The Accomodation of Students(最大匹配 + 二分图判断)
http://acm.hdu.edu.cn/showproblem.php?pid=2444 The Accomodation of Students Time Limit:1000MS Me ...
- hdu 2444 The Accomodation of Students 判断二分图+二分匹配
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
随机推荐
- C语言|博客作业5
---恢复内容开始--- 一.本周教学内容&目标 第2章 用C语言编写程序-函数 2.5 生成乘方表与阶乘表.使学生对函数的定义和调用有初步的认识,能模仿编程. 二.本周作业头 问题 答案 这 ...
- spring注解开发:容器中注册组件方式
1.包扫描+组件标注注解 使用到的注解如下,主要针对自己写的类 @Controller @Service @Repository @Component @ComponentScan 参考 spring ...
- python的三种创建字典的方法
#创建一个空字典 empty_dict = dict() print(empty_dict) #用**kwargs可变参数传入关键字创建字典 a = dict(one=,two=,three=) pr ...
- HDU多校训练第一场 1012 Sequence
题目链接:acm.hdu.edu.cn/showproblem.php?pid=6589 题意:给出一个长度为n的数组,有m次操作,操作有3种1,2,3,问操作m次后的数组,输出i*a[i]的异或和 ...
- 如何多个router 进行合并?
有时间可能有多个人开发,如果在共用router, 势必会造成合并冲突,可以分开多个router.js ,然后进行合并 // router0.jsconst studyRouter = [ { path ...
- spring 事物(二)—— 编程式事物实现与扩展
简介 使用TransactionTemplate 不需要显式地开始事务,甚至不需要显式地提交事务.这些步骤都由模板完成.但出现异常时,应通过TransactionStatus 的setRollback ...
- 【记录】@Configuration注解作用 mybatis @Param作用
参考地址: 1:https://www.cnblogs.com/duanxz/p/7493276.html 2:https://www.wandouip.com/t5i91156/ 3:https:/ ...
- java23种设计模式(二)-- 建造者模式和原型模式
一.建造者模式 将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创造不同的表示. 特点: (1).在某些属性没有赋值之前,复杂对象不能作为一个完整的产品使用.比如汽车包括方向盘.车门.发动机 ...
- Django创建工程项目以及工作原理
一.Django 创建工作项目 1.创建 North 工程项目 (1)使用CMD命令行,切换到指定路径 django-admin.py startproject north (2)使用pycharm创 ...
- python2和python3中TestSuite().addTest的区别
Python2中unittest.TestSuite().addTest()的参数是这样的:unittest.TestSuite().addTest(TestFun("test_nam&qu ...