Test instructions: There are n boys and n Girls at a dance. At the beginning of each song, all the boys and girls fit into the N-dance ballroom. Every boy will not dance with the same girl for two (or more) dance songs. There are some boys and girls who like each other, while others dislike each other (not "one-way Likes"). Each boy is willing to dance with the K-not-like girls at most, and each girl is willing to dance with the K-not-liked boys at most. Given the information that every pair of boys and girls love each other, how many dances can a ball have?
N<=50,k<=30
Idea: The obvious maximum flow problem
Will each male, female is split into two points, one expresses likes, another expresses does not like
Two-point answer
(s,num[i,1]) traffic is mid
(Num[i,4],t) mid
(num[i,1],num[i,2]) (num[i,3],num[i,4]) k
For each other's favorite i,j:
(num[i,1],num[j,4]) 1
Don't like:
(num[i,2],num[j,3]) 1
Judge Maxflow whether =mid*n can
1 varHead,gap,dis:Array[0..10000] ofLongint;2Vet,next,len,fan:Array[1..200000] ofLongint;3Num:Array[1.. -,1..4] ofLongint;4A:Array[1.. -,1.. -] ofChar;5 N,m,i,l,r,mid,last,s,source,src,tot,k1,j:longint;6 ch:string;7 8 procedureAdd (a,b,c:longint);9 beginTen Inc (TOT); Onenext[tot]:=Head[a]; Avet[tot]:=b; -len[tot]:=C; -head[a]:=tot; the Inc (TOT); -next[tot]:=Head[b]; -vet[tot]:=A; -len[tot]:=0; +head[b]:=tot; - End; + A functionmin (x,y:longint): Longint; at begin - ifX<y Thenexit (x); - exit (y); - End; - - functionDFS (u,aug:longint): Longint; in varE,v,t,val,flow:longint; - begin to ifU=src Thenexit (); +E:=head[u]; val:=s-1; flow:=0; - whileE<>0 Do the begin *v:=Vet[e]; $ ifLen[e]>0 ThenPanax Notoginseng begin - ifdis[u]=dis[v]+1 Then the begin +T:=dfs (V,min (len[e],aug-flow)); Alen[e]:=len[e]-T; thelen[fan[e]]:=len[fan[e]]+T; +flow:=flow+T; - ifDis[source]>=s Thenexit (flow); $ ifAug=flow ThenBreak ; $ End; -val:=min (val,dis[v]); - End; thee:=Next[e]; - End;Wuyi ifflow=0 Then the begin - Dec (Gap[dis[u]]); Wu ifgap[dis[u]]=0 Thendis[source]:=s; -dis[u]:=val+1; About Inc (Gap[dis[u]); $ End; - exit (flow); - End; - A functionMaxflow:longint; + varAns:longint; the begin -Fillchar (Gap,sizeof (GAP),0); $Fillchar (dis,sizeof (DIS),0); thegap[0]:=s; ans:=0; the whileDis[source]<s Doans:=ans+DFS (source,maxlongint); the exit (ans); the End; - in procedurebuild; the varI,j:longint; the begin AboutFillchar (Head,sizeof (head),0); thetot:=0; the fori:=1 toN Do the begin +Add (Num[i,1],num[i,2],k1); -Add (Num[i,3],num[i,4],k1); the End;Bayi fori:=1 toN Do the begin theAdd (Source,num[i,1],mid); -Add (Num[i,4],src,mid); - End; the fori:=1 toN Do the forj:=1 toN Do the ifa[i,j]='Y' ThenAdd (Num[i,1],num[j,4],1) the ElseAdd (Num[i,2],num[j,3],1); - End; the the begin theAssign (input,'bzoj1305.in'); Reset (input);94Assign (output,'Bzoj1305.out'); Rewrite (output); the readln (N,K1); the fori:=1 toN Do the begin98 READLN (CH); About forj:=1 toN Doa[i,j]:=Ch[j]; - End;101 fori:=1 to 200000 Do102 ifIMoD 2=1 Thenfan[i]:=i+1103 Elsefan[i]:=i-1;104 fori:=1 toN Do the forj:=1 to 4 Do106 begin107Inc (s); num[i,j]:=s;108 End;109source:=s+1; src:=s+2; s:=s+2; thel:=0; R:=n; last:=0;111 whileL<=r Do the begin113mid:= (l+r) >>1; the build; the ifMaxflow>=mid*n Then beginLast:=mid; L:=mid+1;End the Elser:=mid-1;117 End;118 Writeln (last);119 close (input); - close (output);121 End.
"BZOJ1305" Dance dancing (Max Stream, split Point, two-part answer)