标签:二分匹配
7 0: (3) 4 5 6 1: (2) 4 6 2: (0) 3: (0) 4: (2) 0 1 5: (1) 0 6: (2) 0 1 3 0: (2) 1 2 1: (1) 0 2: (1) 0
5 2给出他们之间认识关系,求最大两两不认识。#include<stdio.h> #include<vector> #include<string.h> #include<iostream> using namespace std; vector<int>map[1005]; int vist[1005],match[1005]; int find(int u) { for(int j=0;j<map[u].size();j++){ int v=map[u][j]; if(!vist[v]){ vist[v]=1; if(match[v]==-1||find(match[v])) { match[v]=u; return 1; } } } return 0; } int main() { int n,a,b,m,ans; while(scanf("%d",&n)>0) { for(int i=0;i<=n;i++) map[i].clear(),match[i]=-1; for(int i=0;i<n;i++) { scanf("%d: (%d)",&a,&m); while(m--) { scanf("%d",&b); map[a].push_back(b); } } ans=0; for(int i=0;i<n;i++) { memset(vist,0,sizeof(vist)); if(find(i)) ans++; } printf("%d\n",n-ans/2); } }
hdu1068Girls and Boys(二分匹配,最大独立集),布布扣,bubuko.com
hdu1068Girls and Boys(二分匹配,最大独立集)
标签:二分匹配
原文地址:http://blog.csdn.net/u010372095/article/details/38226569