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 ( ...
随机推荐
- jmeter 线程组之间传递动态变化的变量值
http://www.51testing.com/html/01/n-3725501.html https://www.jianshu.com/p/73832bae65af https://blog. ...
- [模板]网络最大流 & 最小费用最大流
我的作业部落有学习资料 可学的知识点 Dinic 模板 #define rg register #define _ 10001 #define INF 2147483647 #define min(x ...
- Aspnetcore下面服务器热更新与配置热加载
原文:Aspnetcore下面服务器热更新与配置热加载 Asp.net的热更新方案Appdomain在aspnetcore中不被支持了 新的方案如下: 配置文件更新选项 reloadOnChange ...
- redis基础及基本命令
什么是redis Redis是一个Key-value存储系统,redis提供了丰富的数据结构,包括string(字符串),list(列表),sets(集合),ordered set(有序集合),has ...
- C# 使用猫拨打电话
主窗口一个textbox与btnstart按钮 代码是使用别人!只是去掉部分不用的!只用于拨号!用于辅助打电话! form1 using System; using System.Collection ...
- Java中"String.equals()“和"=="的区别
Do NOT use the `==`` operator to test whether two strings are equal! It only determines whether or n ...
- CDHkafka脚本
启动客户端的命令 /opt/cloudera/parcels/KAFKA--/bin/kafka-console-producer --broker-list hadoop102:9092 --top ...
- 原生js和jquery
$(document).ready(function() {//jquery的写法 }); (function () { //原生js的写法 })();
- 洛谷P2786 英语1(eng1)- 英语作文
题目背景 蒟蒻HansBug在英语考场上,挠了无数次的头,可脑子里还是一片空白. 题目描述 眼下出现在HansBug蒟蒻面前的是一篇英语作文,然而智商捉急的HansBug已经草草写完了,此时 他发现离 ...
- express框架总结
1.express教程及api : http://www.runoob.com/nodejs/nodejs-express-framework.html 2.nodejs的express自动生成项目框 ...