标签:des style java color strong os
2 3 2 1 2 1 2 3 1 3 3 1 2 1 2 3 1 1 3 1
Case 1: 1 Case 2: 2
解题报告
#include <iostream> #include <cstdio> #include <cstring> #include <queue> #define N 30 #define inf 99999999 using namespace std; int n,m,a[N],flow,pre[N]; int Edge[N][N]; queue<int >Q; int bfs() { while(!Q.empty()) Q.pop(); memset(a,0,sizeof(a)); memset(pre,0,sizeof(pre)); Q.push(1); pre[1]=1; a[1]=inf; while(!Q.empty()) { int u=Q.front(); Q.pop(); for(int v=1;v<=n;v++) { if(!a[v]&&Edge[u][v]>0) { pre[v]=u; a[v]=min(Edge[u][v],a[u]); Q.push(v); } } if(a[n])break; } if(!a[n]) return -1; else return a[n]; } void ek() { int a,i; while((a=bfs())!=-1) { for(i=n;i!=1;i=pre[i]) { Edge[pre[i]][i]-=a; Edge[i][pre[i]]+=a; } flow+=a; } } int main() { int t,i,j,u,v,w,k=1; scanf("%d",&t); while(t--) { flow=0; memset(Edge,0,sizeof(Edge)); scanf("%d%d",&n,&m); for(i=0;i<m;i++) { scanf("%d%d%d",&u,&v,&w); Edge[u][v]+=w; } ek(); printf("Case %d: ",k++); printf("%d\n",flow); } return 0; }
HDU3549_Flow Problem(网络流/EK),布布扣,bubuko.com
标签:des style java color strong os
原文地址:http://blog.csdn.net/juncoder/article/details/37831171