"bzoj1449/2895" [JSOI2009] Team yield/Team budget minimum cost maximum flow

Source: Internet
Author: User

"BZOJ2895" Team budget description in a basketball league, there are N teams, the team's spending is related to their outcome, specifically, the first team of the season total expenditure is ci*x^2+di*y^2,di<=ci. (more wins, more bonuses for players), and X, Y, respectively, indicate the team's outcome this season. Now half of the season, each team scored a[i] victory and B[i] field defeat. And then there's the M game going on. Ask the league team what the minimum total cost is. Input first row n,m next n rows of 4 integers per line a[i],b[i],ci,di and then the M line of two integers per line s,t indicates that there will be a match between the group S and the T-team, noting that there may be multiple matches between the two teams. The minimum value for the output total expenditure. Sample Input
3 3
1 0 2 1
1 1 10 1
0 1 3 3
0 S
2 3
3 1
Sample Output +Data Limitfor 20% of data 2<=n<=10,0<=m<=20for data 2<=n<=5000,0<=m<=1000,0<=di<=ci<=10,0<=a[i],b[i]<=50 of 100%.

The first naive, built a 8-storey cost-flow model, the scare of their own silly ~

There is a not easy to deal with the requirements, that is, each game can only one team to win, then we might as well assume that all teams in the beginning of each game is lost, and then we have m traffic, each flow of traffic to a team on behalf of the team won once, and then very good processing.

#include <cstdio> #include <cstring> #include <iostream> #include <queue>using namespace std; int Cnt,n,m,sum,mf,s,t;int to[1000000],next[1000000],cost[1000000],flow[1000000],pe[10000],pv[10000],head[10000] , Dis[10000];int a[10000],b[10000],c[10000],d[10000],e[10000],inq[10000];queue<int> Q;int Rd () {int ret=0,f=1; Char Gc=getchar (); while (gc< ' 0 ' | | Gc> ' 9 ') {if (gc== '-') F=-f;gc=getchar ();} while (gc>= ' 0 ' &&gc<= ' 9 ') ret=ret*10+gc-' 0 ', Gc=getchar (); return ret*f;} void Add (int a,int b,int c,int d) {to[cnt]=b,cost[cnt]=c,flow[cnt]=d,next[cnt]=head[a],head[a]=cnt++;to[cnt]=a,cost[ cnt]=-c,flow[cnt]=0,next[cnt]=head[b],head[b]=cnt++;} int BFs () {memset (dis,0x3f,sizeof (DIS)), int i,u;q.push (S), Dis[s]=0;while (!q.empty ()) {U=q.front (), Q.pop (), inq[u]=0 ; for (I=head[u];i!=-1;i=next[i]) {if (Dis[to[i]]>dis[u]+cost[i]&&flow[i]) {DIS[TO[I]]=DIS[U]+COST[I],PV [To[i]]=u,pe[to[i]]=i;if (!inq[to[i]]) Q.push (To[i]), Inq[to[i]]=1;}} return dis[t]<0x3f3f3f3f;} int main () {N=rd (), m=rd (); int i,j,a,b; S=0,t=n+m+1;memset (head,-1,sizeof (head)); for (i=1;i<=n;i++) a[i]=rd (), B[i]=rd (), C[i]=rd (), D[i]=rd (); for (i=1;i <=m;i++) A=rd (), B=rd (), E[a]++,e[b]++,add (s,n+i,0,1), add (n+i,a,0,1), add (n+i,b,0,1); for (i=1;i<=n;i++) {sum+= c[i]*a[i]*a[i]+d[i]* (E[i]+b[i]) * (E[i]+b[i]), for (j=1;j<=e[i];j++) Add (i,t,c[i]* (a[i]+j-1) +1)-d[i]* (B[i) +E[I]-J) +1), 1);} while (BFS ()) {mf=1<<30;for (I=t;i!=s;i=pv[i]) mf=min (Mf,flow[pe[i]); Sum+=mf*dis[t];for (I=t;i!=s;i=pv[i]) FLOW[PE[I]]-=MF,FLOW[PE[I]^1]+=MF;} printf ("%d", sum); return 0;}

"bzoj1449/2895" [JSOI2009] Team yield/Team budget minimum cost maximum flow

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.