标签:des style http color os io strong 数据
Description
Input
Output
Sample Input
2 1 1 2 (0,1)20 (1,0)10 (0)15 (1)20 7 2 3 13 (0,0)1 (0,1)2 (0,2)5 (1,0)1 (1,2)8 (2,3)1 (2,4)7 (3,5)2 (3,6)5 (4,2)7 (4,3)5 (4,5)1 (6,0)5 (0)5 (1)2 (3)2 (4)1 (5)4
Sample Output
15 6
Hint
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <algorithm> #include <iostream> #include <queue> using namespace std; #define inf 9999999999 int flow[210][210]; int maxflow[210],father[210],vis[210]; int max_flow; int m,i; void EK(int s,int e) { queue<int >q; int u,v; max_flow=0; while(1) { memset(maxflow,0,sizeof(maxflow)); memset(vis,0,sizeof(vis)); maxflow[s]=inf; q.push(s); while(!q.empty()) { u=q.front(); q.pop(); for(v=s;v<=e;v++) { if(!vis[v]&&flow[u][v]>0) { vis[v]=1; father[v]=u; q.push(v); maxflow[v]=min(maxflow[u],flow[u][v]); } } if(maxflow[e]>0) { while(!q.empty()) q.pop(); break; } } if(maxflow[e]==0) break; for(i=e;i!=s;i=father[i]) { flow[father[i]][i]-=maxflow[e]; flow[i][father[i]]+=maxflow[e]; } max_flow+=maxflow[e]; } } int main() { int n,np,nc,m; int i,a,b,c; char ch; while(~scanf("%d%d%d%d ",&n,&np,&nc,&m))//输入注意后面的空格 { memset(flow,0,sizeof(flow)); for(i=1;i<=m;i++) { scanf("(%d,%d)",&a,&b); scanf("%d ",&c);//注意后面的空格 flow[a+1][b+1]=c; } for(i=1;i<=np;i++)//建立总源点 { scanf("(%d)%d ",&a,&b);//注意后面空格 flow[0][a+1]=b; } for(i=1;i<=nc;i++)//建立总汇点 { scanf("(%d)%d ",&a,&b);//注意后面的空格 flow[a+1][n+1]=b; } EK(0,n+1); printf("%d\n",max_flow); } return 0; }
Power Network(最大流基础_增广路算法:多源多汇,自建总源点和总汇点),布布扣,bubuko.com
Power Network(最大流基础_增广路算法:多源多汇,自建总源点和总汇点)
标签:des style http color os io strong 数据
原文地址:http://blog.csdn.net/u013486414/article/details/38670053