Question:
For several power stations, for several consumption stations, and for several forwarding points.
Power stations only generate electricity, and consume only power consumption. The forwarding point only forwards electricity to each transmission line.
Ask how much electricity you can obtain when consuming a site.
Ideas:
Add a super source point and a super sink point .. Connect the power station to the super source point, and connect the war of consumption to the super sink point ..
Note that the input format is correct!
#include<stdio.h>#include<string.h>#include<queue>using namespace std;#define inf 10000000#define min(a,b) a<b?a:bint map[210][210],maxf[210],pre[210];int n,m,nc,np; int bfs(){int i;queue<int>q;for(i=0;i<=n+1;i++){maxf[i]=inf;pre[i]=-1;}pre[0]=0;q.push(0);while(!q.empty()){int qian=q.front();q.pop();int hou;for(hou=1;hou<=n+1;hou++){if(map[qian][hou]&&pre[hou]==-1){pre[hou]=qian;maxf[hou]=min(maxf[qian],map[qian][hou]);q.push(hou);}}}if(pre[n+1]==-1)return 0;return maxf[n+1];}int ek(){int max=0,kejia;while(kejia=bfs()){max+=kejia;int index=n+1,qian;while(index!=0){qian=pre[index];map[qian][index]-=kejia;map[index][qian]+=kejia;index=qian;}}return max;}int main(){int i,ans,u,v,w;char ch[10];while(scanf("%d %d %d %d",&n,&nc,&np,&m)!=EOF){memset(map,0,sizeof(map));for(i=0;i<m;i++){scanf("%s",ch);sscanf(ch,"(%d,%d)%d",&u,&v,&w);map[u+1][v+1]=w;}for(i=0;i<nc;i++){scanf("%s",ch);sscanf(ch,"(%d)%d",&u,&w);map[0][u+1]=w;}for(i=0;i<np;i++){scanf("%s",ch);sscanf(ch,"(%d)%d",&v,&w);map[v+1][n+1]=w;}ans=ek();printf("%d\n",ans);}return 0;}