/*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. Scrapy框架: 通用爬虫之CrawlSpider

    步骤01: 创建爬虫项目 scrapy startproject quotes 步骤02: 创建爬虫模版 scrapy genspider -t quotes quotes.toscrape.com ...

  2. 原生AJAX的封装

    /**调用AJAX ajaxPlug.openajax({ url: "./TestXHR.aspx", //请求地址 type: "POST", //请求方式 ...

  3. WEBRTC三种类型(Mesh、MCU 和 SFU)的多方通信架构

    WebRTC 本身提供的是 1 对 1 的通信模型,在 STUN/TURN 的辅助下,如果能实现 NAT 穿越,那么两个浏览器是可以直接进行媒体数据交换的:如果不能实现 NAT 穿越,那么只能通过 T ...

  4. 60.Median of Two Sorted Arrays(两个排序数组的中位数)

    Level:   Hard 题目描述: There are two sorted arrays nums1 and nums2 of size m and n respectively. Find t ...

  5. 重读ORB_SLAM之LoopClosing线程难点

    1. DetectLoop 这里有个ConsistenGroup概念,比较难懂.这里是最让人迷惑的地方.一旦vbConsistentGroup为真,其他帧的spCanditateGroup就进不来了. ...

  6. C#socket客户端自己输入消息发送到服务端通信实现通信

    一,服务端代码 using System; using System.Collections.Generic; using System.Linq; using System.Text; using ...

  7. db2别名&同义词

    创建别名: create alias alias_name  for tab_name|view_name... 删除别名: drop alias alias_name 创建同义词(synonym): ...

  8. Mac中的brew

    最近要研究字体识别tesseract,才了解到brew,惭愧惭愧. 1.brew是一个软件包管理工具,类似于centos下的yum或者ubuntu下的apt-get,非常方便,免去了自己手动编译安装的 ...

  9. .net Core AJAX使用Header传递参数,以JsonResult返回信息

    function postHeader() { $.ajax({ url : "/myTest/PostHeader?time="+ (new date()).getTime(), ...

  10. 绘图matplotlib

    前言 matplotlib是python的一个绘图库,如果你没有绘制过图,可以先试试js的绘图库http://www.runoob.com/highcharts/highcharts-line-lab ...