hdu 2444 The Accomodation of Students 二分图判断 + 最大匹配
来源:互联网 发布:淘宝卖减肥药有要求吗 编辑:程序博客网 时间:2024/05/16 18:00
题目链接
题意:给定n个点,m条无向边。首先判断能否得到一个二分图(BFS),如果可以,则进行二分图匹配。
#include <stdio.h>#include <string.h>#include <math.h>#include <iostream>#include <algorithm>using namespace std;typedef long long LL;const int maxn = 205;const int Mod = 1000000007;int n,m;bool vis[maxn];int cx[maxn],cy[maxn];int map[maxn][maxn],c[maxn];bool bipartite( int u ){for( int i = 1; i <= n; i ++ ){if( map[u][i] ){if( c[u] == c[i] )return false;if( !c[i] ){c[i] = 3 - c[u];if( !bipartite(i) ) return false; }}}return true;}int findpath( int u ){for( int i = 1; i <= n; i ++ ){if( c[i] == 2 && map[u][i] && !vis[i] ){vis[i] = 1;if( cy[i] == -1 || findpath( cy[i] ) ){cy[i] = u;cx[u] = i;return true;}}}return false;}int MaxMatch(){int ans = 0;memset( cx,-1,sizeof(cx) );memset( cy,-1,sizeof(cy) );for( int i = 1; i <= n; i ++ ){if( c[i] == 1 && cx[i] == -1 ){memset( vis,0,sizeof(vis) );ans += findpath( i );}}return ans;}int main(){int a,b;while( scanf("%d%d",&n,&m) != EOF ){memset( c,0,sizeof(c) );memset( map,0,sizeof(map) );for( int i = 0; i < m; i ++ ){scanf("%d%d",&a,&b);map[a][b] = map[b][a] = 1;}int ok = 1;for( int i = 1; i <= n; i ++ ){if( c[i] == 0 )c[i] = 1;if( !bipartite( i ) )ok = 0;}if( ok ){printf("%d\n",MaxMatch());}elseputs("No");}return 0;}
0 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(二分图判断+最大匹配)
- sencha touch 2 xtype一览
- 面试智力题(三)
- 开通csdn博客
- uva 350(数学)
- CodeForces 425A Sereja and Swaps
- hdu 2444 The Accomodation of Students 二分图判断 + 最大匹配
- 线性回归标准方程及其概率解释
- UVA10453- Make Palindrome
- android sdk离线安装
- OpenStack 各个组件作用
- Fibonacci的两种实现方式:递归和递推
- 强参数 Strong parameters: Dealing with mass assignment in the controller instead of the model
- 192.0x00c8.0x00c8.0x00fa
- spring mvc配置