二分图最大匹配匈牙利算法模板两种
2014-06-04 14:27
253 查看
1.邻接表(vector向量法)
View Code
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 1007 int path ,vis ; int match ; int n,m; int Search_Path(int s) { for(int i=1;i<=m;i++) { if(path[s][i] && !vis[i]) { vis[i] = 1; if(match[i] == -1 || Search_Path(match[i])) { match[i] = s; return 1; } } } return 0; } int main() { int cnt,i,j,k; int a,b; while(scanf("%d",&k)!=EOF && k) { scanf("%d%d",&n,&m); memset(match,-1,sizeof(match)); memset(path,0,sizeof(path)); for(i=0;i<k;i++) { scanf("%d%d",&a,&b); path[a][b] = 1; } cnt = 0; for(i=1;i<=n;i++) { memset(vis,0,sizeof(vis)); if(Search_Path(i)) cnt++; } printf("%d\n",cnt); } return 0; }
View Code
相关文章推荐
- 二分图最大匹配之匈牙利算法模板
- 二分图最大匹配 匈牙利算法模板
- 【模板】二分图最大匹配(匈牙利算法)
- 二分图最大匹配匈牙利算法(poj)3041(模板)
- 匈牙利算法模板 二分图最大匹配
- 【模板】匈牙利算法 二分图最大匹配题模板
- 透彻解析二分图最大匹配匈牙利算法模板
- 求二分图最大匹配——匈牙利算法模板。
- hihocoder #1122 二分图二•二分图最大匹配之匈牙利算法(*【模板】应用 )
- 【模板】匈牙利算法——二分图最大匹配
- 51Nod 飞行员配对(二分图最大匹配)(匈牙利算法模板题)
- POJ 1469 COURSES【匈牙利算法入门 二分图的最大匹配 模板题】
- 二分图最大匹配(匈牙利算法Dfs模板)
- 二分图最大匹配算法-匈牙利算法(Hungary)模板
- 匈牙利算法求二分图的最大匹配/匈牙利算法模板
- [模板] + [详解] - 二分图最大匹配 - 匈牙利算法
- 匈牙利算法,二分图最大匹配、多重匹配模板
- 二分图最大匹配模板(匈牙利算法)
- (模板题)poj 3041 Asteroids(二分图的最大匹配匈牙利算法)
- NYOJ 题目239 月老的难题 (二分图最大匹配-匈牙利算法模板)