标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 14306 Accepted Submission(s): 6319
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 using namespace std; 5 int map[1010][1010]; //邻接矩阵存储关系; 6 int dis[1010]; //记录已匹配点的编号。 7 int vis[1010]; //标记数组; 8 int n, v; 9 bool Search(int a) 10 { 11 for(int i = 1; i <= v; i++) 12 { 13 if(map[a][i] && !vis[i]) //i与a相邻且未被标记; 14 { 15 vis[i] = 1; 16 if(dis[i] == 0 || Search(dis[i])) //i未出现在前一个匹配中 || i出现在前一个匹配中但从与i相邻的节点可能会有增广路; 17 { 18 dis[i] = a; 19 return true; 20 } 21 } 22 } 23 return false; 24 } 25 int main() 26 { 27 int m; 28 while(~scanf("%d", &m), m) 29 { 30 memset(map, 0, sizeof(map)); 31 memset(dis, 0, sizeof(dis)); 32 scanf("%d %d", &n, &v); 33 for(int i = 1; i <= m; i++) 34 { 35 int a, b; 36 scanf("%d %d", &a, &b); 37 map[a][b] = 1; 38 } 39 int cnt = 0; 40 for(int i = 1; i <= n; i++) 41 { 42 memset(vis, 0, sizeof(vis)); 43 if(Search(i)) 44 cnt++; 45 } 46 printf("%d\n", cnt); 47 } 48 return 0; 49 }
标签:
原文地址:http://www.cnblogs.com/fengshun/p/4743308.html