【二分匹配】 HDU 2444 The Accomodation of Students
来源:互联网 发布:linux c pipe 编辑:程序博客网 时间:2024/05/29 18:34
点击打开链接
求两个集合,使得一个集合内的任意两个人互不认识。
最大独立集==1 输出 No。
#include <cstdio>#include <cstring>#include <cstdlib>#include <string>#include <iostream>#include <algorithm>#include <sstream>#include <cmath>using namespace std;#include <queue>#include <stack>#include <set>#include <vector>#include <deque>#include <map>#define cler(arr, val) memset(arr, val, sizeof(arr))typedef long long LL;const int MAXN = 210;const int MAXM = 140000;const int INF = 0x3f3f3f3f;const LL mod = 10000007;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1int mp[MAXN][MAXN];int linker[MAXN],vN,uN;bool used[MAXN];bool dfs(int u)//从左边开始找增广路径{ int v; for(v=0;v<vN;v++)//这个顶点编号从0开始,若要从1开始需要修改 if(mp[u][v]&&!used[v]) { used[v]=true; if(linker[v]==-1||dfs(linker[v])) {//找增广路,反向 linker[v]=u; return true; } } return false;//这个不要忘了,经常忘记这句}int hungary(){ int res=0; int u; memset(linker,-1,sizeof(linker)); for(u=0;u<uN;u++) { memset(used,0,sizeof(used)); if(dfs(u)) res++; } return res;}int col[MAXN];bool check(int x,int c){ col[x]=!c; for(int i=0;i<vN;i++) { if(mp[x][i]) { if(col[i]==col[x]) return false; else if(col[i]==!col[x]) continue; if(!check(i,!c)) return false; } } return true;}int main(){ int n,m; while(cin>>n>>m) { int a,b; cler(mp,0); cler(col,-1); vN=uN=n; for(int i=1;i<=m;i++) { cin>>a>>b; a--,b--; mp[a][b]=mp[b][a]=1; } col[0]=1; if(!check(0,1)) puts("No"); else { int ans=hungary(); cout<<ans/2<<endl; } }}
0 0
- hdu 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 2444The Accomodation of Students 二分匹配+dfs分组
- 【二分匹配】 HDU 2444 The Accomodation of Students
- hdu 2444 The Accomodation of Students(二分匹配)
- HDU 2444 The Accomodation of Students 二分匹配
- hdu 2444 The Accomodation of Students 【二分图匹配】
- hdu2444 二分匹配 The Accomodation of Students
- 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 二分图判定+二分匹配个数
- c语言 之 双向链表 简单操作
- 浅一谈百度索引量和收录量的区别
- 如何安装和学习OpenStack?
- Jfreecharts简单使用
- WIN7+64位+ndk配置
- 【二分匹配】 HDU 2444 The Accomodation of Students
- axure6.5汉化最新正式破解版本下载(有注册码)
- 在xcode6.1和ios10.10.1环境下实现app发布
- mapreduce编程:wordcount
- java - 小乌龟
- 一个PHP+jQuery+Ajax+Json综合实例
- 判断IOS的网络和电量状况
- 微信营销成本与影响力成正比
- oracle express edition 11g无法打开127.0.0.1:8080