HDU 2444 The Accomodation of Students(判断二分图&染色法)
来源:互联网 发布:21lic单片机项目外包网 编辑:程序博客网 时间:2024/06/05 21:11
题目大意:给定一些关系,问能有没有最大匹配。
思路:二分图匹配,用染色法判断奇环(因为二分图不会有奇环)
#include<map>#include<queue>#include<cmath>#include<iostream>#include<cstdio>#include<stack>#include<cstring>#include<algorithm>#define LL long long#define inf 0x3f3f3f3fconst double PI=acos(-1.0);using namespace std;struct node{ int to,next;}q[50000];int cnt,head[50000],cro[50000],col[50000];bool vis[50000];void bu(int a,int b){ q[cnt].to=b; q[cnt].next=head[a]; head[a]=cnt++;}int dfs(int u){ for(int i=head[u];~i;i=q[i].next){ int v=q[i].to; if(vis[v]) continue; vis[v]=true; if(cro[v]==-1||dfs(cro[v])){ cro[v]=u; return 1; } } return 0;}bool color(int x){ for(int i=head[x];~i;i=q[i].next){ int u=q[i].to; if(!col[u]){ col[u]=!col[x]; if(!color(u)) return false; } else if(col[x]==col[u]){ return false; } } return true;}int main(){ int n,m,i,j,k,a,b,ans; while(~scanf("%d%d",&n,&m)){ cnt=ans=0; memset(head,-1,sizeof(head)); memset(col,0,sizeof(col)); for(i=0;i<m;i++){ scanf("%d %d",&a,&b); bu(a,b);bu(b,a); } //col[1]=1; bool bj=false; for(i=1;i<=n;i++){ if(!color(i)){ bj=true;break; //puts("No");continue; } } if(bj){ puts("No");continue; } memset(cro,-1,sizeof(cro)); for(i=1;i<=n;++i){ memset(vis,false,sizeof(vis)); ans+=dfs(i); } printf("%d\n",ans/2); } return 0;}
0 0
- HDU 2444 The Accomodation of Students(判断二分图&染色法)
- HDU-2444-The Accomodation of Students [二分匹配][判断二分图][BFS染色法]
- 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 (二分图最大匹配+二分图染色)
- HDU2444 The Accomodation of Students(染色法判断二分图+最大匹配)
- HDU2444 The Accomodation of Students(染色法判断二分图)
- 【染色法+二分图匹配】hdu 2444 The Accomodation of Students
- hdu 2444 The Accomodation of Students (交叉染色+二分匹配)
- HDOJ 题目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【二分图染色+匹配*好题】
- Android线程三、Handler
- iOS此证书的签发者无效
- 《大话设计模式》——简单工厂模式1
- POJ 3669 Meteor Shower
- RAD Studio 10 自带Demo代码汇总说明
- HDU 2444 The Accomodation of Students(判断二分图&染色法)
- 数字图像处理--显示图像矩阵出现的问题
- booj 1350 【POJ1113】墙
- php的一些魔术方法的使用
- 数据结构学习笔记——二叉树的遍历
- TCP/IP协议三次握手流程
- flv文件AVCDecoderConfigurationRecord以及AudioSpecificConfig结构
- 关于mysql下载后没有my.ini文件解决方案
- 安卓时间处理