hdu 2444The Accomodation of Students 二分图判定+找最大匹配
来源:互联网 发布:linux安全狗 编辑:程序博客网 时间:2024/06/10 18:42
#include<bits/stdc++.h>using namespace std;int t;int link[100010];//记录前驱结点bool vis[100010];int n,m;int color[100010];vector<int>v[100101];bool dfs(int x){ int i,j; for(i=0;i<v[x].size();i++) { if(vis[v[x][i]]==0) { vis[v[x][i]]=1; if(link[v[x][i]]==-1||dfs(link[v[x][i]]))//如果没有被访问,说明找到新的交错轨,进行增广。否则,继续找他的前驱是否有其他增广轨。 { link[v[x][i]]=x; return true; } } } return false;}void multi_path(){ memset(link,-1,sizeof(link)); int i,j; int ans=0; for(i=1;i<=n;i++) { memset(vis,0,sizeof(vis)); if(dfs(i)) ans++; } cout<<(ans/2)<<endl;}bool judge(){ int i,j; memset(color,-1,sizeof(color)); for(i=1;i<=n;i++) { if(color[i]==-1)//最开始染一种颜色 { color[i]=0; } for(j=0;j<v[i].size();j++) { if(color[v[i][j]]==-1)//判断是否染色,-1表示没有染色,没有就燃一个相反地颜色 { color[v[i][j]]=1-color[i];//染成相反地颜色 } else if(color[v[i][j]]==color[i])//如果找到两个颜色相同,说明不是二分图,返回 { return 1; } } } return 0;}int main(){ std::ios::sync_with_stdio(false); while(cin>>n>>m) { int i,j; for(i=1;i<=n;i++) v[i].clear(); int x,y; for(i=0;i<m;i++) { cin>>x>>y; v[x].push_back(y); v[y].push_back(x); } if(judge()) { cout<<"No"<<endl; continue; } multi_path(); }}
0 0
- hdu 2444The 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 (二分图判定+最大匹配
- The Accomodation of Students(HDU-2444)(二分图判定与最大匹配)
- 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【二分图染色+最大二分匹配数】
- 搭建Xilinx交叉编译环境
- linux svn cmd
- Eclipse快捷键 10个最有用的快捷键
- 陈力:传智播客古代 珍宝币 泡泡龙游戏开发第十三讲:盒子的定位实例
- poj 1845
- hdu 2444The Accomodation of Students 二分图判定+找最大匹配
- HTML5游戏总结:分辨率对游戏布局设计的影响
- 南阳oj 数据结构 括号配对 题目2 NYOJ
- pascal+sublime搭建Pascal学习环境
- Android studio 快捷键
- HDU4152-Happy 2004-积性函数和快速幂乘
- 开发板上的tftp 上传和下载用法
- system/WIFEXITED/WEXITSTATUS函数-linux
- 求连续数中偶数的平方和,奇数的立方和