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