网络流演示

1

 

  1. #include <stdio.h>  
  2. #include <string.h>  
  3. #define MAX 102  
  4.    
  5. long n,n1,match;  
  6. long adjl[MAX][MAX];  
  7. long mat[MAX];  
  8. bool used[MAX];  
  9.    
  10. FILE *fi,*fo;  
  11.    
  12. void readfile()  
  13. {  
  14.     fi=fopen("flyer.in","r");  
  15.     fo=fopen("flyer.out","w");  
  16.     fscanf(fi,"%ld%ld",&n,&n1);  
  17.     long a,b;  
  18.     while (fscanf(fi,"%ld%ld",&a,&b)!=EOF)  
  19.         adjl[a][ ++adjl[a][0] ]=b;  
  20.     match=0;  
  21. }  
  22.    
  23. bool crosspath(long k)  
  24. {  
  25.     for (long i=1;i<=adjl[k][0];i++)  
  26.     {  
  27.         long j=adjl[k][i];  
  28.         if (!used[j])  
  29.         {  
  30.             used[j]=true;  
  31.             if (mat[j]==0 || crosspath(mat[j]))  
  32.             {  
  33.                 mat[j]=k;  
  34.                 return true;  
  35.             }  
  36.         }  
  37.     }  
  38.     return false;  
  39. }  
  40.    
  41. void hungary()  
  42. {  
  43.     for (long i=1;i<=n1;i++)  
  44.     {  
  45.         if (crosspath(i))  
  46.             match++;  
  47.         memset(used,0,sizeof(used));  
  48.     }  
  49. }  
  50.    
  51. void print()  
  52. {  
  53.     fprintf(fo,"%ld",match);  
  54.     fclose(fi);  
  55.     fclose(fo);  
  56. }  
  57.    
  58. int main()  
  59. {  
  60.     readfile();  
  61.     hungary();  
  62.     print();  
  63.     return 0;  
  64. }  

 





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值