Thinking of solving problems
It should be more obvious that this is a network flow, will be $s$ with the room, the room with the people, the people and the food side, food and meeting point edge, edge of the flow of 1. But this is wrong, because it is possible for a person to run past 2 of the traffic, so the person will be removed to limit the flow.
#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<queue>using namespacestd;Const intMAXN =505;Const intMAXM =50005;Const intINF =0x3f3f3f3f; inlineintRd () {intx=0;CharCh=GetChar (); while(!isdigit (CH)) ch=GetChar (); while(IsDigit (CH)) {x= (x<<1) + (x<<3) +ch-'0'; ch=GetChar ();} returnx;}intN,p,q,head[maxn],cnt=1,to[maxm<<1],nxt[maxm<<1],val[maxm<<1];intans,s,t= -, D[maxn];queue<int>Q;inlinevoidAddintBgintEdintW) {to[++cnt]=ed,nxt[cnt]=head[bg],val[cnt]=w,head[bg]=CNT;} InlineBOOLBFs () { while(Q.size ()) Q.pop (); memset (d,0,sizeof(d)); d[s]=1; Q.push (S); while(Q.size ()) {intx=Q.front (); Q.pop (); for(RegisterintI=head[x];i;i=Nxt[i]) { intu=To[i]; if(!d[u] &&Val[i]) {D[u]=d[x]+1; Q.push (U); if(u==t)return true; } } } return false;}intDinic (intXintflow) { if(x==t)returnflow; intres=flow,k; for(RegisterintI=head[x];i && res;i=Nxt[i]) { intu=To[i]; if(d[u]==d[x]+1&&Val[i]) {k=dinic (U,min (Val[i],flow)); if(!k) d[u]=0; Val[i]-=k;val[i^1]+=k;res-=K; } } returnflow-Res;}intMain () {n=rd (), P=rd (), Q=rd ();intx; for(intI=1; i<=p;i++) Add (S,i,1), add (I,s,0); for(intI=1; i<=n;i++) for(intj=1; j<=p;j++) {x=rd ();if(!x)Continue; Add (J,i+p,1), add (I+p,j,0); } for(intI=1; i<=n;i++) Add (I+p,i+p+n,1), add (I+p+n,i+p,0); for(intI=1; i<=n;i++) for(intj=1; j<=q;j++) {x=rd ();if(!x)Continue; Add (i+p+n,j+n*2+p,1), Add (j+n*2+p,i+p+n,0); } for(intI=1; i<=q;i++) Add (i+n*2+p,t,1), Add (t,i+n*2+p,0); while(BFS ()) ans+=dinic (S,inf); cout<<ans; return 0;}View Code
The King of Luogu P1402 Hotel (Network stream)