zoj 1137 Girls and Boys 二分图的最大独立集
2013-08-25 09:03
288 查看
#include <iostream> #include <cstdio> #include <cstring> using namespace std; #define SIZE 505 int n; int graph[SIZE][SIZE]; int visited[SIZE]; int match[SIZE]; int Hungary(int u){ int i; for(i = 0; i < n; i++){ if(!visited[i] && graph[u][i]){ visited[i] = 1; if(match[i] == -1 || Hungary(match[i])){ match[i] = u; return 1; } } } return 0; } int main(){ //freopen("in.txt", "r", stdin); while(cin>>n){ int i, j; memset(graph, 0, sizeof(graph)); memset(match, -1, sizeof(match)); for(i = 0; i < n; i++){ int stu, knowN, tmp_know; scanf("%d: (%d)", &stu, &knowN); for(j = 0; j < knowN; j++){ cin>>tmp_know; graph[i][tmp_know] = 1; } } int ans = 0; for(i = 0; i < n; i++){ memset(visited, 0, sizeof(visited)); if(Hungary(i)) ans++; } cout<<n - ans / 2<<endl; //除2很关键,因为算了两遍 } return 0; }
相关文章推荐
- POJ 1466 && ZOJ 1137--Girls and Boys【二分图 && 最大点独立集】
- ZOJ 1137 Girls and Boys(二分图最大独立集)
- hdu 1068 zoj 1137 poj 1466 Girls and Boys(二分图匹配 匈牙利算法 最大独立集)
- zoj - 1137 - Girls and Boys(二分图最大独立点集)
- HDU1068/POJ1466_Girls and Boys(二分图/最大独立集=N-最大匹配)
- POJ 1466 Girls and Boys(二分图最大独立集)
- hdu1068 Girls and Boys (二分图最大独立集)
- zoj 1137 Girls and Boys(poj 1466)(最大独立点集)
- POJ - 1466 Girls and Boys 二分图+最大独立集
- HDU 1068 Girls and Boys (二分图最大独立集)
- (step6.3.2)hdu 1068(Girls and Boys——二分图的最大独立集)
- HDU 1068 Girls and Boys 二分图 最大独立集 字符串
- POJ 1466 Girls and Boys【二分图_最大独立集】
- POJ-1466-Girls and Boys(二分图最大独立集)
- HDU 1068 Girls and Boys 二分图最大独立集(最大二分匹配)
- HDU1068,POJ1466——Girls and Boys(二分图最大独立集)
- HDOJ题目1068Girls and Boys(二分图最大独立集,匈牙利算法模板)
- POJ 1466 Girls and Boys(二分图最大独立集)
- POJ 1466:Girls and Boys 二分图的最大点独立集
- hdoj1068 Girls and Boys(二分图+最大独立集)