Bzoj 3504 Dangerous Bridge

Source: Internet
Author: User

Must pay attention to the INF to open very large. Otherwise... Hey, heh.

Because the traffic may cross, then b1,b2 to run again.

1 A is cool.

#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<queue>#defineMAXV 650#defineMaxe 250500#defineINF 9999999999999999using namespacestd;structedge{Long LongV,F,NXT;} E[maxe];Long LongG[maxv],n,a1,a2,an,b1,b2,bn,nume=1, map[ -][ -],s,t,flag;Long LongDis[maxv];queue<Long Long>Q;BOOLVIS[MAXV];Charss[ -];voidAddedge (Long LongULong LongVLong Longf) {e[++nume].v=W; E[NUME].F=F; E[NUME].NXT=G[u]; G[u]=Nume; e[++nume].v=u; E[NUME].F=0; E[NUME].NXT=G[v]; G[V]=Nume;}voidBuildLong Longtype) {memset (g,0,sizeof(g)); Nume=1;  for(Long LongI=1; i<=n;i++)         for(Long Longj=1; j<=n;j++)            if(map[i][j]==1) Addedge (I,j,2); Else if(map[i][j]==2) Addedge (I,j,inf); Addedge (S,A1,2*an); Addedge (A2,t,2*an ); if(type==1) {Addedge (S,B1,2*BN); Addedge (B2,t,2*bn);} Else{Addedge (S,B2,2*BN); Addedge (B1,t,2*bn);}}BOOLBFs () { while(!q.empty ()) Q.pop (); Fill (Dis+1, dis+t+1,-1); memset (Vis,false,sizeof(VIS)); Q.push (s);d Is[s]=0; vis[s]=true;  while(!Q.empty ()) {        Long LongHead=Q.front ();        Q.pop ();  for(Long LongI=g[head];i;i=e[i].nxt) {            Long Longv=e[i].v; if((E[I].F) && (vis[v]==false) ) {Dis[v]=dis[head]+1; VIS[V]=true;            Q.push (v); }        }    }    if(dis[t]==-1)return false; return true;}Long LongDinic (Long LongXLong LongLow ) {    if(x==t)returnLow ; Else    {        Long Longret=0;  for(Long LongI=g[x];i;i=e[i].nxt) {            Long Longv=e[i].v; if((E[I].F) && (dis[v]==dis[x]+1))            {                Long LongDd=dinic (V,min (LOW,E[I].F)); E[I].F-=dd;e[i^1].f+=DD; RET+=dd;low-=DD; }        }        if(ret==0) dis[x]=-1; returnret; }}voidWorkLong Longtype) {    Long Longret=0;    Build (type);  while(BFS ()) RET+=dinic (S,inf); if(ret==an*2+bn*2) flag=1; Elseflag=0;}intMain () { while(SCANF ("%lld%lld%lld%lld%lld%lld%lld", &n,&a1,&a2,&an,&b1,&b2,&bn)! =EOF) {A1++;a2++;b1++;b2++; Flag=0; memset (Map,0,sizeof(map)); S=0; t=n+1;  for(Long LongI=1; i<=n;i++) {scanf ("%s", SS);  for(Long Longj=0; j<n;j++)            {                if(ss[j]=='O') map[i][j+1]=1; Else if(ss[j]=='N') map[i][j+1]=2; }} work (1); if(flag==1) Work (2); if(flag==1) printf ("yes\n"); Elseprintf"no\n"); }    return 0;}

Bzoj 3504 Dangerous Bridge

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.