Poj 1459 Power Network (max Stream)

Source: Internet
Author: User

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;} 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.