标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 19166 Accepted Submission(s): 8369
1 //2016.9.16 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5 #define N 1005 6 7 using namespace std; 8 9 int e[N][N], match[N], book[N], k, n, m; 10 11 int dfs(int u) 12 { 13 for(int i = 1; i <= n; i++) 14 { 15 if(book[i]==0 && e[u][i]==1) 16 { 17 book[i] = 1; 18 if(match[i] == 0 || dfs(match[i])) 19 { 20 match[i] = u; 21 return 1; 22 } 23 } 24 } 25 return 0; 26 } 27 28 int main() 29 { 30 int a, b; 31 while(scanf("%d", &k)!=EOF && k) 32 { 33 int ans = 0; 34 scanf("%d%d", &m, &n); 35 memset(e, 0, sizeof(e)); 36 for(int i = 0; i < k; i++) 37 { 38 scanf("%d%d", &a, &b); 39 e[a][b] = 1; 40 } 41 memset(match, 0, sizeof(match)); 42 for(int i = 1; i <= m; i++) 43 { 44 memset(book, 0, sizeof(book)); 45 if(dfs(i))ans++;//找到一条增广路 46 } 47 printf("%d\n", ans); 48 } 49 50 return 0; 51 }
标签:
原文地址:http://www.cnblogs.com/Penn000/p/5877549.html