HDU 2444 The Accomodation of Students(二分图判断+最大二分匹配)
来源:互联网 发布:安卓原笔迹手写软件 编辑:程序博客网 时间:2024/05/29 21:30
The Accomodation of Students
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5145 Accepted Submission(s): 2341
Problem Description
There are a group of students. Some of them may know each other, while others don’t. For example, A and B know each other, B and C know each other. But this may not imply that A and C know each other.
Now you are given all pairs of students who know each other. Your task is to divide the students into two groups so that any two students in the same group don’t know each other.If this goal can be achieved, then arrange them into double rooms. Remember, only paris appearing in the previous given set can live in the same room, which means only known students can live in the same room.
Calculate the maximum number of pairs that can be arranged into these double rooms.
Input
For each data set:
The first line gives two integers, n and m(1
#include<cstdio>#include<cstring>#include<queue>#include<algorithm>using namespace std;int e[205][205],n,m,color[205],match[205],book[205];int bfs(int x){ memset(color,0,sizeof(color)); queue<int>q; int fr,ne; q.push(x); color[x]=1; while(!q.empty()) { fr=q.front(); q.pop(); for(int i=1;i<=n;i++) { if(e[fr][i]==1) { if(color[i]==0) { color[i]=3-color[fr]; q.push(i); } else { if(color[i]==color[fr]) { return 0; } } } } } return 1;}int dfs(int u){ for(int i=1;i<=n;i++) { if(book[i]==0&&e[u][i]==1) { book[i]=1; if(match[i]==-1||dfs(match[i])) { match[i]=u; return 1; } } } return 0;}int main(){ while(~scanf("%d%d",&n,&m)) { memset(e,0,sizeof(e)); int u,v; for(int i=0;i<m;i++) { scanf("%d%d",&u,&v); e[u][v]=1; } int re=bfs(1); if(re==0) { printf("No\n"); } else { memset(match,-1,sizeof(match)); int sum=0; for(int i=1;i<=n;i++) { memset(book,0,sizeof(book)); if(dfs(i)) { sum++; } } printf("%d\n",sum); } } return 0;}
- hdu 2444 The Accomodation of Students(判断二分图,二分图最大匹配)
- hdu 2444 The Accomodation of Students(二分图判断,二分图最大匹配)
- HDU 2444 The Accomodation of Students(二分图判断+最大二分匹配)
- hdu 2444 The Accomodation of Students(二分图判断+求最大匹配)
- hdu 2444 The Accomodation of Students (判断是否是二分图,最大匹配)
- HDU - 2444 The Accomodation of Students(二分图判断+最大匹配)
- HDU 2444 The Accomodation of Students(判断是否为二分图+最大匹配)
- HDU 2444 The Accomodation of Students(判断是否是二分图及求最大匹配)
- HDU 2444 The Accomodation of Students 判断是否为二分图,二分图的最大匹配
- hdu 2444 The Accomodation of Students (判断二分图,二分图最大匹配)
- HDU-2444 The Accomodation of Students(二分图判断+最大二分匹配)
- HDU 2444 The Accomodation of Students(最大二分匹配(匈牙利算法)+二分图判断->模板题目)
- HDU 2444 The Accomodation of Students (二分图最大匹配+二分图染色)
- HDU 2444 The Accomodation of Students 判断二分图 + 最大匹配
- hdu 2444 The Accomodation of Students 二分图判断 + 最大匹配
- hdu 2444 The Accomodation of Students 判断是否为二分图+最大匹配
- hdu 2444 The Accomodation of Students 【二分图判断+求最大匹配】
- hdu 2444 The Accomodation of Students (判断二分图+最大匹配)
- php 时间戳
- OpenWrt支持usb tethering
- Java Web中如何访问WEB-INF下的XML文件
- 设为首页代码和加入收藏JS代码(未测试)
- 斐波拉契数列=>多种方法的比较(分治、递归、动态规划/递推)
- HDU 2444 The Accomodation of Students(二分图判断+最大二分匹配)
- 写点日志--word 操作
- ROS by example- 第三章: 操作系统和ROS版本
- 安卓集成极光推送SDK基础服务
- HDU 5742 It's All In The Mind (水题)
- BufferedWriter/Reader and FileWriter/Reader
- 北斗系统基础知识1(北斗系统定位原理说明“图文详述”)
- 高仿微信抢红包动画特效
- 【机器学习入门】局部加权回归