poj Girls and Boys 二分图匹配
2015-09-04 15:17
393 查看
[code]#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; int n,p[1024],g[1024][1024],cx[1024],cy[1024],my[1024]; int dfs(int u) { int v; for(v=0;v<n;v++) { if(g[u][v]==1&&my[v]==0) { my[v]=1; if(cy[v]==-1||dfs(cy[v])) { cx[u]=v; cy[v]=u; return 1; } } } return 0; } int MaxMatch() { int i,res=0; memset(cx,0xff,sizeof(cx)); memset(cy,0xff,sizeof(cy)); for(i=0;i<n;i++) { if(cx[i]==-1) { memset(my,0,sizeof(my)); res+=dfs(i); } } return res; } int main() { int i,j,t,m; while(~scanf("%d",&n)) { memset(p,0xff,sizeof(p)); memset(g,0,sizeof(g)); for(i=0;i<n;i++) { scanf("%d: (%d)",&t,&m); if(m==0) continue; for(j=0;j<m;j++) { scanf("%d",&t); g[t][i]=g[i][t]=1; } } int ans=MaxMatch(); if(ans%2==1) ans++; printf("%d\n",n-ans/2); } return 0; }
相关文章推荐
- cinのpeek putback
- UVa 524:Prime Ring Problem(回溯)
- [leetcode 220]Contains Duplicate III
- Linux 进程间通信(一)(经典IPC:管道、FIFO)
- poj Girls and Boys 二分图匹配
- 在VS2010中的MFC中配置GDI+
- 使用iptables配置linux服务器请求转发
- web 前端学习笔记(1)
- php 高级研发工程师面试题总结
- STM32中assert_param的使用
- crontab 定时完成某任务
- 小胖说事38----tableview:ios7 分割线短 15 像素(废弃) ios8方法如何将分割线还原
- HDU 1695 GCD(莫比乌斯反演)
- Objective-C类,NSUrl介绍和使用
- NDK开发之字符串操作
- NDK开发之字符串操作
- android:ellipsize属性的含义
- Qt信号与槽
- NDK开发之字符串操作
- NDK开发之字符串操作