Bzoj 1305 Dance Dance

Source: Internet
Author: User

Network flow.

First, the answer to the question is whether the X-ray dance is feasible.

Consider building a map, set three points for each person, representing the whole, like and dislike.

The source point connects a single edge of X to each boy's point.

The whole point of each boy likes to point to a side with a capacity of positive infinity and a side with a capacity of K to dislike points.

Every boy likes to point to all the girls he likes. A side that has a capacity of one, does not like to point to all the girls he doesn't like. Don't like to point to a one-size side.

Each girl likes to point to the whole point with a positive infinity edge, and does not like to point the whole point to a single edge with a capacity of K.

Each girl's whole point to a meeting point is an X-size edge.

Check is the determination of whether the maximum stream equals n*x.

In this case, the definition of flow is the number of dance, the whole point to the Yuanhui point of the edge to ensure that each round is exactly paired with n pairs, such as a round in the presence of a female student corresponding to multiple boys, the final maximum flow will be reduced.

#include <cstring>#include<cstdio>#include<algorithm>#include<iostream>#include<queue>using namespacestd;Const intdian=305;Const intbian=40005;Const intinf=0x3f3f3f3f;intN,k,tot;ints,t;intH[dian],nxt[bian],ver[bian],val[bian],ch[dian];Charmap[ -][ -];voidAddintCanintBbintcc) {Tot++;ver[tot]=bb;val[tot]=cc;nxt[tot]=h[aa];h[aa]=tot; Tot++;ver[tot]=aa;val[tot]=0; nxt[tot]=h[bb];h[bb]=tot;}intBhintAaintPintOK) {    return(aa-1)*3+p+ok*3*N;}BOOLTell () {memset (ch,-1,sizeof(CH)); Queue<int>Q;    Q.push (S); Ch[s]=0;  while(!Q.empty ()) {        intt=Q.front ();        Q.pop ();  for(intI=h[t];i;i=Nxt[i])if(ch[ver[i]]==-1&&Val[i])                {Q.push (ver[i]); Ch[ver[i]]=ch[t]+1; }    }    returnch[t]!=-1;}intZengintAintb) {    if(a==T)returnb; intR=0;  for(intI=h[a];i&&b>r;i=Nxt[i])if(ch[ver[i]]==ch[a]+1&&Val[i]) {            intT=zeng (Ver[i],min (b-r,val[i])); Val[i]-=t,r+=t,val[i^1]+=T; }    if(!r) Ch[a]=-1; returnR;}intDinic () {intR=0, T;  while(Tell ()) while(t=Zeng (S,inf)) R+=T; returnR;}BOOLCheckintmid) {memset (NXT,0,sizeof(NXT)); memset (H,0,sizeof(h)); Tot=1;  for(intI=1; i<=n;i++) {Add (S,BH (i,1,0), mid); Add (BH (i,1,1), T,mid); Add (BH (i,1,0), BH (i,2,0), INF); Add (BH (i,1,0), BH (i,3,0), k); Add (BH (i,2,1), BH (i,1,1), INF); Add (BH (i,3,1), BH (i,1,1), k); }     for(intI=1; i<=n;i++)         for(intj=1; j<=n;j++){            if(map[i][j]=='Y') Add (BH (i,2,0), BH (J,2,1),1); ElseAdd (BH (i,3,0), BH (J,3,1),1); }    if(Dinic () ==n*mid)return true; return false;}intBinintLintR) {    intmid;  while(l<R) {Mid= (l+r+1) >>1; if(check (mid)) L=mid; ElseR=mid-1; }    returnl;}intMain () {scanf ("%d%d",&n,&k); S=6*n+1, t=6*n+2;  for(intI=1; i<=n;i++) scanf ("%s", map[i]+1); printf ("%d", Bin (0, -)); return 0;}

Bzoj 1305 Dance Dance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.