题目传送门
。
解法:
一看到这题。
大喊一声“不是建完图跑一下网络流吗”
朱老师走过来拍了拍我:如果a1流到b2呢,反过来就行了。。
反过来??什么鬼??
emmmm好吧然后我弃疗了去颓了。
又看到这题了。。
什么鬼啊。。
反过来??
哦反过来。。
反过来好像行。。
那么正常建完图之后呢。
再把b1b2反过来就行了啊。
如果原来串流了。那么反过来肯定不会串流。
代码实现:
#include
#include
#include
#include
#include
#include
#include
using namespace std;
struct node {int x,y,c,next,other;}a[110000];int len,last[110];
void ins(int x,int y,int c) {
int k1,k2;
len++;k1=len;a[len].x=x;a[len].y=y;a[len].c=c;a[len].next=last[x];last[x]=len;
len++;k2=len;a[len].x=y;a[len].y=x;a[len].c=0;a[len].next=last[y];last[y]=len;
a[k1].other=k2;a[k2].other=k1;
}
int head,tail,list[110],st,ed,h[110];
bool bt_h() {
head=1;tail=2;list[1]=st;memset(h,0,sizeof(h));h[st]=1;
while(head!=tail) {
int x=list[head];
for(int k=last[x];k;k=a[k].next) {
int y=a[k].y;
if(h[y]==0&&a[k].c>0) {h[y]=h[x]+1;list[tail++]=y;}
}head++;
}if(h[ed]==0)return false;return true;
}
int find_flow(int x,int f) {
if(x==ed)return f;
int s=0,t;
for(int k=last[x];k;k=a[k].next) {
int y=a[k].y;
if(h[y]==h[x]+1&&a[k].c>0&&sy,min(a[k].c,f-s));s+=t;a[k].c-=t;a[a[k].other].c+=t;
}
}if(s==0)h[x]=0;return s;
}
char map[110][110];int n,a1,a2,an,b1,b2,bn;
void build() {
len=0;memset(last,0,sizeof(last));
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++) {
if(map[i][j]=='O')ins(i,j,2);else if(map[i][j]=='N')ins(i,j,999999999);
}
}
int main() {
while(scanf("%d",&n)!=EOF) {
scanf("%d%d%d%d%d%d",&a1,&a2,&an,&b1,&b2,&bn);
a1++;a2++;b1++;b2++;
for(int i=1;i<=n;i++)scanf("%s",map[i]+1);
st=n+1;ed=st+1;build();
ins(st,a1,2*an);ins(a2,ed,2*an);
ins(st,b1,2*bn);ins(b2,ed,2*bn);
int ans=0;while(bt_h()==true)ans+=find_flow(st,999999999);
if(ans<2*(an+bn))printf("No\n");
else {
build();
ins(st,a1,2*an);ins(a2,ed,2*an);
ins(st,b2,2*bn);ins(b1,ed,2*bn);
int ans=0;while(bt_h()==true)ans+=find_flow(st,999999999);
if(ans<2*(an+bn))printf("No\n");
else printf("Yes\n");
}
}
return 0;
}