The topic probably said that there are N men n women, every round of men to dance with different women, men and women have their own likes to dance with the object, they can tolerate and k not like the people dance, ask the ball can be a few rounds.
Binary enumeration round with maximum flow judgment: male and female each split into two points I, I ' and J, J ', the side of the middle continuous volume k; the edge of the source point to I with the number of rounds, J ' to the edge of the meeting point of the number of rounds; if I and J are like relations then I to the side of the J ' even capacity 1, otherwise I ' to the side of the J-1; If the result equals n the number of rounds is set.
1#include <cstdio>2#include <cstring>3#include <queue>4#include <algorithm>5 using namespacestd;6 #defineINF (1<<30)7 #defineMAXN 4448 #defineMAXM 444*8889 Ten structedge{ One intV,cap,flow,next; A }EDGE[MAXM]; - intVs,vt,ne,nv; - intHEAD[MAXN]; the - voidAddedge (intUintVintcap) { -Edge[ne].v=v; Edge[ne].cap=cap; edge[ne].flow=0; -Edge[ne].next=head[u]; head[u]=ne++; +Edge[ne].v=u; edge[ne].cap=0; edge[ne].flow=0; -EDGE[NE].NEXT=HEAD[V]; head[v]=ne++; + } A at intLEVEL[MAXN]; - intGAP[MAXN]; - voidBFs () { -memset (level,-1,sizeof(level)); -Memset (Gap,0,sizeof(GAP)); -level[vt]=0; ingap[level[vt]]++; -queue<int>que; to Que.push (VT); + while(!Que.empty ()) { - intu=Que.front (); Que.pop (); the for(intI=head[u]; i!=-1; I=Edge[i].next) { * intv=edge[i].v; $ if(level[v]!=-1)Continue;Panax Notoginsenglevel[v]=level[u]+1; -gap[level[v]]++; the Que.push (v); + } A } the } + - intPRE[MAXN]; $ intCUR[MAXN]; $ intIsap () { - BFS (); -memset (pre,-1,sizeof(pre)); thememcpy (Cur,head,sizeof(head)); - intu=pre[vs]=vs,flow=0, aug=INF;Wuyigap[0]=NV; the while(level[vs]<NV) { - BOOLflag=false; Wu for(int&i=cur[u]; i!=-1; I=Edge[i].next) { - intv=edge[i].v; About if(Edge[i].cap!=edge[i].flow && level[u]==level[v]+1){ $flag=true; -pre[v]=u; -u=v; - //aug= (Aug==-1?edge[i].cap:min (Aug,edge[i].cap)); AAug=min (aug,edge[i].cap-edge[i].flow); + if(v==VT) { theflow+=; - for(u=pre[v]; V!=vs; v=u,u=Pre[u]) { $edge[cur[u]].flow+=; theedge[cur[u]^1].flow-=; the } the //Aug=-1; theaug=INF; - } in Break; the } the } About if(flag)Continue; the intMinlevel=NV; the for(intI=head[u]; i!=-1; I=Edge[i].next) { the intv=edge[i].v; + if(Edge[i].cap!=edge[i].flow && level[v]<minlevel) { -Minlevel=Level[v]; thecur[u]=i;Bayi } the } the if(--gap[level[u]]==0) Break; -level[u]=minlevel+1; -gap[level[u]]++; theu=Pre[u]; the } the returnflow; the } - intn,m,k; the BOOLg[111][111]; the //vs I i+n i+2*n i+3*n vt the BOOLisOKintt) {94Xss0; vt=n*4+1; nv=vt+1; Ne=0; thememset (head,-1,sizeof(head)); the for(intI=1; i<=n; ++i) { the Addedge (vs,i,t);98Addedge (i,i+n,k); AboutAddedge (i+2*n,i+3*n,k); -Addedge (i+3*n,vt,t);101 }102 for(intI=1; i<=n; ++i) {103 for(intj=1; j<=n; ++j) {104 if(G[i][j]) Addedge (i,j+3*n,1); the ElseAddedge (i+n,j+2*n,1);106 }107 }108 returnISAP () ==t*N;109 } the intMain () {111 intt,a,b; thescanf"%d",&t);113 while(t--){ thescanf"%d%d%d",&n,&m,&k); thememset (G,0,sizeof(G)); the while(m--){117scanf"%d%d",&a,&b);118g[a][b]=1;119 } - intL=0, r=N;121 while(l<R) {122 intmid=l+r+1>>1;123 if(isOK (mid)) l=mid;124 Elser=mid-1; the }126printf"%d\n", L);127 } - return 0;129}
HUST1024 Dance Party (Max Stream)