hdu 2444 The Accomodation of Students 二分匹配
来源:互联网 发布:数据开发工程师笔试题 编辑:程序博客网 时间:2024/05/20 05:29
题意:
给出一些关系朋友对,问是否能够将朋友分成两组,且各组内人员没有任何关系!!
解法:
判断各朋友下的关系朋友,是否存在关系!!如果存在,输出No,否则输出最大匹配数@
#include<iostream>#include<cstdio>#include<memory.h>#include<algorithm>using namespace std;int vis[202],mat[202],map[202][202];int n,m,k;int f[1002][1002];int find(int x){ for(int i=f[x][0]; i>=1; i--) { int y=f[x][i]; if(!vis[y]) { vis[y]=1; if(mat[y]==-1||find(mat[y])) { mat[y]=x; return 1; } } } return 0;}int main(){ int i,j,k,ni,mi,ki,ans; while(scanf("%d%d",&n,&m)!=EOF) { memset(f,0,sizeof(f)); memset(mat,-1,sizeof(mat)); memset(map,0,sizeof(map)); // memset(vis,-1,sizeof(vis)); ans=0; for(j=1; j<=m; j++) { scanf("%d%d",&ni,&mi); map[ni][mi]=1; f[ni][++f[ni][0]]=mi; } int flag=0; for(i=1; i<=n&&!flag; i++) { for(j=f[i][0]; j>=1&&!flag; j--) { int x=f[i][j]; for(k=f[i][0]; k>=1; k--) { int y=f[i][k]; if(map[x][y]) { flag=1; break; } } } } if(flag) { cout<<"No"<<endl; continue; } for(i=1; i<=n; i++) { memset(vis,0,sizeof(vis)); if(find(i)) ans++; } printf("%d\n",ans); } return 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 二分图判定+二分匹配个数
- 内容过滤器
- spring hessian应用
- 玩转Google开源C++单元测试框架Google Test系列(gtest)之二 - 断言
- 玩转Google开源C++单元测试框架Google Test系列(gtest)之三 - 事件机制
- wince 经常遇到了一些编译错误
- hdu 2444 The Accomodation of Students 二分匹配
- 属性过滤器(Attribute Filters)
- 玩转Google开源C++单元测试框架Google Test系列(gtest)之四 - 参数化
- 用栈实现队列
- Weblogic报错VALIDATION PROBLEMS WERE FOUND problem: cvc-complex-type.2.4a: Expected elements解决方法
- 表单域Forms过滤
- 玩转Google开源C++单元测试框架Google Test系列(gtest)之五 - 死亡测试
- HTTP 返回状态值
- SOAP三