记录编号 177876 评测结果 AAAAAAAAAA
题目名称 运输问题1 最终得分 100
用户昵称 Gravatarforever 是否通过 通过
代码语言 C++ 运行时间 0.008 s
提交时间 2015-08-12 20:41:17 内存使用 0.35 MiB
显示代码纯文本
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstdlib>
  4. #include<cstring>
  5. #include<queue>
  6. using namespace std;
  7. int as[102][102],deep[102],flow,a;
  8. int n,h;
  9. bool bfs()
  10. {
  11. queue<int>q;
  12. memset(deep,-1,sizeof(deep));
  13. deep[1]=1;
  14. q.push(1);
  15. while(!q.empty())
  16. {
  17. int yu=q.front();
  18. q.pop();
  19. for(int i=1;i<=n;++i)
  20. {
  21. if(as[yu][i]&&deep[i]<0)
  22. {
  23. deep[i]=deep[yu]+1;
  24. q.push(i);
  25. }
  26. }
  27. }
  28. if(deep[n]>0) return true;
  29. return false;
  30. }
  31. int find(int s,int low)
  32. {
  33. if(s==n) return low;
  34. for(int i=1;i<=n;++i)
  35. {
  36. if(deep[i]==deep[s]+1&&as[s][i])
  37. {
  38. if(a=find(i,min(low,as[s][i])))
  39. {
  40. as[s][i]-=a;
  41. as[i][s]+=a;
  42. return a;
  43. }
  44. }
  45. }
  46. return 0;
  47. }
  48. int main()
  49. { freopen("maxflowa.in" ,"r",stdin ) ;
  50. freopen("maxflowa.out","w",stdout) ;
  51. scanf("%d",&n);
  52. for(int i=1;i<=n;++i)
  53. for(int j=1;j<=n;++j)
  54. scanf("%d",&as[i][j]);
  55. while(bfs())
  56. {
  57. while(h=find(1,9999999)) flow+=h;
  58. }
  59. printf("%d",flow);
  60. }