标签:des style color os io for ar art
二分图模板,剩下的就是建图的过程。
int dfs(int a) { int i; for(i=0;i<n;i++) { if(!vis[i]&&mapp[a][i]) { vis[i] = 1; if(dis[i]==-1||dfs(dis[i])) { dis[i] = a; return 1; } } } return 0; }
#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; int mapp[500][500]; int vis[1100],dis[1100]; int n; int dfs(int a) { int i; for(i=0;i<n;i++) { if(!vis[i]&&mapp[a][i]) { vis[i] = 1; if(dis[i]==-1||dfs(dis[i])) { dis[i] = a; return 1; } } } return 0; } int main() { int a,b,c; int sum; int i,j; while(scanf("%d",&n)!=EOF) { sum = 0; memset(mapp,0,sizeof(mapp)); for(j=0;j<n;j++) { scanf("%d: (%d) ",&a,&b); for(i=1; i<=b; i++) { scanf("%d",&c); mapp[a][c] = 1; } } memset(dis,-1,sizeof(dis)); for(i=0;i<n;i++) { memset(vis,0,sizeof(vis)); if(dfs(i)) { sum++; } } // printf("%d\n%d\n",n,sum); printf("%d\n",n-sum/2); } return 0; }
Description
Sample Input
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
Sample Output
5 2
二分图基础--Girls and Boys,布布扣,bubuko.com
标签:des style color os io for ar art
原文地址:http://blog.csdn.net/fq0909/article/details/38585249