HDU 2444 判断是否为二分图
来源:互联网 发布:北航软件考研分数线 编辑:程序博客网 时间:2024/06/05 14:03
题意:给你n,m,问是否为二分图,若是找出他的最大二分匹配。。。。
#include <queue>#include <cstring>#include <iostream>using namespace std;const int N = 220;int col[N], g[N][N],n,m;int ans[N],vis[N],sum;int queu[N],judge[N];//0为白色,1为黑色 bool bfs(){ //二分图BFS判断 queue<int> p;memset(col, -1, sizeof(col)); p.push(1); col[1] = 0; while(!p.empty()) { int from = p.front(); p.pop(); for(int i = 1; i <= n; i++) { if(g[from][i] && col[i] == -1) { p.push(i); col[i] = (col[from]+1)%2;//染成不同的颜色 }else if(g[from][i] && col[from] == col[i])//颜色有相同,则不是二分图 return false; } } return true; }int dfs(int id){ for(int i=1;i<=n;i++) { if(vis[i]==0&&g[id][i]) { vis[i]=1; if(ans[i]==-1||dfs(ans[i])) { ans[i]=id; return 1; } } } return 0;}int main() { int a, b, i; while(cin >> n >> m) { memset(g,0,sizeof(g)); for(i = 0; i < m; i++) { cin >> a >> b; g[a][b] = g[b][a] = 1; }if(!bfs()){ cout << "No" <<endl; continue;}sum=0;memset(ans,-1,sizeof(ans));for(int i=1;i<=n;i++){memset(vis,0,sizeof(vis));if(dfs(i)) sum++;}cout<<sum/2<<endl;}return 0;}
0 0
- HDU 2444 判断是否为二分图
- HDU 2444 The Accomodation of Students 判断是否为二分图,二分图的最大匹配
- HDU 4751 Divide Groups(判断是否为二分图)
- 判断是否为二分图
- 判断是否为二分图
- 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 (二分图匹配+匈牙利算法+bfs判断是否为二分图)
- 判断一个图是否为二分图
- 判断是否为二分图 染色法
- NYOJ-1015(判断是否为二分图)
- HDU 2444 The Accomodation of Students 判断是否为二分匹配+求最大匹配数
- HDU 2444 判断是否是二分图以及二分最大匹配
- UVA 10004判断一个图是否为二分图
- 判断一个无向图是否为二分图
- hdu5971 Wrestling Match (判断是否为二分图)
- Tomcat中“Offending class: javax/servlet/Servlet.class”错误:重复的servlet包
- OTcl与C++,NS2是如何识别并调用执行协议的
- Collection of debates on O_DIRECT.
- HDU 1754 I Hate It (线段树)
- C++内存泄露,查询检查机制
- HDU 2444 判断是否为二分图
- linux操作常用技巧汇总
- Xcode 5 如何禁用某个文件ARC(Automatic Reference Counting)
- linux下setUid知识点
- AppleScript学习笔记(四)条件语句和循环语句
- Leetcode_power(x,n)
- 浙大PAT 1034 Head of aGang
- javascript推荐书籍
- SharePoint 2013中修改windows 活动目录(AD)域用户密码的WebPart(免费下载)