/*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 二分图判定 + 二分图最大匹配 即二分图-安排房间的更多相关文章

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

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

  2. (匹配)The Accomodation of Students --HDU --2444

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=2444 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  3. B - The Accomodation of Students - hdu 2444(最大匹配)

    题意:现在有一些学生给你一下朋友关系(不遵守朋友的朋友也是朋友),先确认能不能把这些人分成两组(组内的人要相互不认识),不能分的话输出No(小写的‘o’ - -,写成了大写的WA一次),能分的话,在求 ...

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

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

  5. HDU2444(KB10-B 二分图判定+最大匹配)

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

  6. [hdu4598]二分图判定,差分约束

    题意: 给一个图,问能否给每个点分配一个实数值,使得存在一个数实数T,所有点满足:|value(i)| < T 且 u,v之间有边<=> |value(u)-value(v)| &g ...

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

    题目来源:HDU 2444 The Accomodation of Students 题意:n个人能否够分成2组 每组的人不能相互认识 就是二分图判定 能够分成2组 每组选一个2个人认识能够去一个双人 ...

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

    http://acm.hdu.edu.cn/showproblem.php?pid=2444 The Accomodation of Students Time Limit:1000MS     Me ...

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

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

随机推荐

  1. hdu3555 Bomb(数位dp)

    题目传送门 Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total ...

  2. VMware Converter Standalone迁移概要

    VMware Converter 迁移工具使用:1.基本概念 1.1基本组件: converter standalone server:包含server和worker两个服务,这两个服务经常一起安装 ...

  3. js 页面跳转 新窗口打开

    页面跳转:Window.showModalDialog(url,width,height); 弹出一个html文档的模式对话框Parent.window.document.location.href ...

  4. Flask-Login的实现

    Flask-Login Flask-Login 为 Flask 提供用户 session 的管理机制.它可以处理 Login.Logout 和 session 等服务. 作用: 将用户的 id 储存在 ...

  5. String 字符串和StringBuffer的知识点总结

    String字符串 1  字符串.equals();                                                   equals和length的区别:equals ...

  6. 关于python接口测试connect error

    接口测试里如果报错出现 socket.gaierror: [Errno 8] nodename nor servname provided, or not known 或者 urllib3.excep ...

  7. C++ 字符串截取转换及字符流控制

    文章由来 ------------------工作需要缓冲区里的字符串控制,还是混合编译的那种,根据协议来定义截取各种字符流,控制大小长度,截取返回的内容然后转换成特定的类型, 可能表述不是那么正确, ...

  8. Vue项目中导入excel文件读取成js数组

    1. 安装组件 cnpm install xlsx --save 2. 代码 <template> <span> <input class="input-fil ...

  9. 【leetcode】1006. Clumsy Factorial

    题目如下: Normally, the factorial of a positive integer n is the product of all positive integers less t ...

  10. html2canvas截图白边显示问题

    html2canvas(document.getElementById('resource_chart'),{ useCORS:true, logging:false, width:$('#resou ...