"Bzoj" "1449" "JSOI2009" team benefits

Source: Internet
Author: User

Network flow/cost flow/two min right matching

Puzzle: http://blog.csdn.net/huzecong/article/details/9119741

Oh, God! Because a win a bad to build the map, first assume that all lose, and then will win the proceeds to modify! It becomes a normal two-point map!!

Cost is related to the square of the flow of the split edge ... This can be done a little bit.

1 /**************************************************************2 problem:14493 User:tunix4 language:c++5 result:accepted6 time:676 Ms7 memory:3940 KB8 ****************************************************************/9  Ten //Bzoj 1449 One#include <cmath> A#include <vector> -#include <cstdio> -#include <cstring> the#include <cstdlib> -#include <iostream> -#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) + #defineF (i,j,n) for (int i=j;i<=n;++i) - #defineD (i,j,n) for (int i=j;i>=n;--i) + #definePB Push_back A #defineCC (A, B) memset (A,b,sizeof (a)) at using namespacestd; - intGetint () { -     intv=0, sign=1;CharCh=GetChar (); -      while(!isdigit (CH)) {if(ch=='-') sign=-1; Ch=GetChar ();} -      while(IsDigit (CH)) {v=v*Ten+ch-'0'; Ch=GetChar ();} -     returnv*Sign ; in } - Const intn=10000, m=100000, inf=~0u>>2; totypedefLong LongLL; + Const Doubleeps=1e-8; - /*******************template********************/ the intN,m,w[n],l[n],c[n],d[n],du[n]; * LL ans; $ structedge{int  from, To,v,c;};Panax Notoginseng structnet{ - Edge E[m]; the     inthead[n],next[m],cnt; +     voidInsintXintYintZintc) { Ae[++cnt]=(Edge) {x,y,z,c}; theNEXT[CNT]=HEAD[X]; head[x]=CNT; +     } -     voidAddintXintYintZintc) { $Ins (x,y,z,c); Ins (y,x,0,-c); $     } -     intS,t,d[n], from[n],q[m]; -     BOOLInq[n]; the     BOOLSPFA () { -         intL=0, r=-1;WuyiF (I,0, T) d[i]=INF; thed[s]=0; Q[++r]=s; inq[s]=1; -          while(l<=R) { Wu             intX=q[l++]; inq[x]=0; -              for(intI=head[x];i;i=Next[i]) About                 if(E[I].V && d[x]+e[i].c<D[e[i].to]) { $d[e[i].to]=d[x]+e[i].c; -                      from[e[i].to]=i; -                     if(!Inq[e[i].to]) { -q[++r]=e[i].to; Ainq[e[i].to]=1; +                     } the                 } -         } $         returnd[t]!=INF; the     } the     voidmcf () { the         intx=INF; the          for(intI= from[t];i;i= from[E[i]. from]) -x=min (x,e[i].v); in          for(intI= from[t];i;i= from[E[i]. from]){ thee[i].v-=x; thee[i^1].v+=x; About         } theans+=x*D[t]; the     } the     voidinit () { +N=getint (); M=getint (); Cnt=1; ans=0; -s=0; t=n+m+1; theF (I,1, N) {BayiW[i]=getint (); l[i]=getint (); theC[i]=getint ();d [i]=getint (); the //Ans+=w[i]*w[i]*c[i]+l[i]*l[i]*d[i]; -         } -         intx, y; theF (I,1, M) { theX=getint (); y=getint (); thedu[x]++; du[y]++; theAdd (X,i+n,1,0); Add (Y,i+n,1,0); -Add (I+n,t,1,0); thel[x]++; l[y]++; the         } theF (I,1, N) ans+=w[i]*w[i]*c[i]+l[i]*l[i]*D[i];94           theF (I,1, N) F (J,1, Du[i]) theAdd (S,i,1, ((J+w[i]) *2-1) *c[i]-((l[i]-j+1)*2-1)*d[i]); the          while(SPFA ()) MCF ();98printf"%lld\n", ans); About     } - }g1;101 intMain () {102 #ifndef Online_judge103Freopen ("Input.txt","R", stdin);104 //freopen ("Output.txt", "w", stdout); the #endif106 g1.init ();107     return 0;108}
View Code

"Bzoj" "1449" "JSOI2009" team benefits

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.