Bzoj1449 [JSOI2009] Team Benefits

Source: Internet
Author: User

Time Limit:5 Sec Memory limit:64 MB
submit:741 solved:423 Descriptioninputoutput An integer that represents the minimum value of the sum of all the teams in the league. Sample Input3 3
1 0 2 1
1 1 10 1
0 1 3 3
0 S
2 3
3 1
Sample Output43
HINT

Source

Minimum cost maximum flow.

The game will bring benefits to the team, making it extremely difficult to build the side. Consider the conversion problem, first of all, assume that the result of each game is "both sides to lose", as the initial state, then the decision of a team to win, then the gain is "win the income-loss of income."

1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cmath>5#include <queue>6#include <cstring>7 using namespacestd;8 Const intinf=1e8;9 Const intmxn=9000;Ten intRead () { One     intx=0, f=1;CharCh=GetChar (); A      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} -      while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} -     returnx*F; the } - structedge{ -     int  from, V,NXT; -     intf,w; +}e[mxn<<1]; - inthd[mxn],mct=1;// + voidAdd_edge (intUintVintCintW) { AE[++MCT].V=V;E[MCT]. from=U;E[MCT].NXT=HD[U];E[MCT].F=C;E[MCT].W=W;HD[U]=MCT;return; at } - // - intn,m; - ints,t; - intans=0; - intWIN[MXN],LOSE[MXN],C[MXN],D[MXN]; in // - intDIS[MXN]; to BOOLINQ[MXN]; + intpre[mxn<<1]; - voidSPFA (ints) { thememset (DIS,0x3f,sizeofdis); *memset (pre,-1,sizeofpre); $queue<int>Q;Panax Notoginsengdis[s]=0; -inq[s]=1; the Q.push (s); +      while(!Q.empty ()) { A         intU=q.front (); Q.pop (); inq[u]=0; the          for(intI=hd[u];i;i=e[i].nxt) { +             if(!E[I].F)Continue; -             intv=e[i].v; $             if(dis[v]>dis[u]+E[I].W) { $dis[v]=dis[u]+E[I].W; -Pre[v]=i;//record the precursor edge -                 if(!Inq[v]) { theinq[v]=1; - Q.push (v);Wuyi                 } the             } -         } Wu     } -     return; About } $ voidMaxflow (intSintt) { - SPFA (s); -      while(pre[t]!=-1){ -         inttmp=INF; A          for(inti=pre[t];i!=-1; I=pre[e[i]. from]) +tmp=min (tmp,e[i].f); theans+=dis[t]*tmp; -          for(inti=pre[t];i!=-1; I=pre[e[i]. from]){ $e[i].f-=tmp; thee[i^1].f+=tmp; the         } the SPFA (s); the     } -     return; in } the intA[MXN],B[MXN]; the intMain () About { the     inti,j,u,v; theN=read (); m=read (); the      for(i=1; i<=n;i++){ +Win[i]=read (); lose[i]=read (); -C[i]=read ();d [i]=read (); the     }Bayi      for(i=1; i<=m;i++){ theA[i]=read (); b[i]=read (); the++lose[a[i]];++Lose[b[i]]; -     } -      for(i=1; i<=n;i++) {//assuming it's all lost . theans+=c[i]*win[i]*Win[i]; theans+=d[i]*lose[i]*Lose[i]; the     } thes=0; t=m+n+2; -      for(i=1; i<=m;i++){ theAdd_edge (S,i,1,0); theAdd_edge (I,s,0,0); theAdd_edge (I,m+a[i],1,0);94Add_edge (M+a[i],i,0,0); theAdd_edge (I,m+b[i],1,0); theAdd_edge (M+b[i],i,0,0); the         //a98         intcost=c[a[i]]* (2*win[a[i]]+1)-d[a[i]]* (2*lose[a[i]]-1); AboutAdd_edge (M+a[i],t,1, cost); -Add_edge (T,m+a[i],0,-Cost );101win[a[i]]++;lose[a[i]]--;102         //b103cost=c[b[i]]* (2*win[b[i]]+1)-d[b[i]]* (2*lose[b[i]]-1);104Add_edge (M+b[i],t,1, cost); theAdd_edge (T,m+b[i],0,-Cost );106win[b[i]]++;lose[b[i]]--;107     }108 Maxflow (s,t);109printf"%d\n", ans); the     return 0;111}

Bzoj1449 [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.