标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 17258 | Accepted: 9386 |
Description
Input
Output
Sample Input
3 4 1 1 1 3 2 2 3 2
Sample Output
2
Hint
1 #include <iostream> 2 #include<stdio.h> 3 #include<string.h> 4 using namespace std; 5 int map[500][500]; 6 int vis[500],match[500]; 7 int m,n; 8 int DFS(int p){ 9 int v; 10 for(int i=1;i<=m;i++){ 11 if(map[p][i]&&!vis[i]){ 12 vis[i]=1; 13 v=match[i]; 14 if( v==-1 || DFS(v)){ 15 match[i]=p; 16 return 1; 17 } 18 19 } 20 } 21 return 0; 22 } 23 int main() { 24 while(~scanf("%d %d",&m,&n)){ 25 memset(map,0,500*500*sizeof(int)); 26 for(int i=0;i<n;i++){ 27 int a,b; 28 scanf("%d %d",&a,&b); 29 map[a][b]=1; 30 } 31 int result=0; 32 memset(match,-1,500*sizeof(int)); 33 for(int i=1;i<=m;i++){ 34 memset(vis,0,500*sizeof(int)); 35 result+=DFS(i); 36 } 37 printf("%d\n",result); 38 } 39 return 0; 40 }
Asteroids - poj 3041(二分图最大匹配问题)
标签:
原文地址:http://www.cnblogs.com/sdxk/p/4669419.html