Exercises
Poke here: http://blog.csdn.net/huzecong/article/details/9119741?
Code:
1#include <cstdio>2#include <cstdlib>3#include <cmath>4#include <cstring>5#include <algorithm>6#include <iostream>7#include <vector>8#include <map>9#include <Set>Ten#include <queue> One#include <string> A #defineINF 1000000000 - #defineMAXN 100000+5 - #defineMAXM 100000+5 the #defineEPS 1e-10 - #definell Long Long - #definePA pair<int,int> - #defineFor0 (i,n) for (int i=0;i<= (n); i++) + #defineFor1 (i,n) for (int i=1;i<= (n); i++) - #defineFor2 (i,x,y) for (int i= (x); i<= (y); i++) + #defineFor3 (i,x,y) for (int i= (x); i>= (y); i--) A #defineFor4 (i,x) for (int i=head[x],y;i;i=e[i].next) at #defineMoD 1000000007 - using namespacestd; -InlineintRead () - { - intx=0, f=1;CharCh=GetChar (); - while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} in while(ch>='0'&&ch<='9') {x=Ten*x+ch-'0'; ch=GetChar ();} - returnx*F; to } + intn,m,k,mincost,tot=1, S,T,A[MAXN],B[MAXN],C[MAXN],D[MAXN],SS[MAXN],HEAD[MAXN], from[2*MAXM]; - BOOLV[MAXN]; thequeue<int>Q; * structedge{int from, Go,next,v,c;} e[2*MAXM]; $ voidInsintXintYintZintW)Panax Notoginseng { -E[++tot]= (Edge) {x,y,head[x],z,w};head[x]=tot; the } + voidInsertintXintYintZintW) A { theIns (x,y,z,w); Ins (Y,x,0,-W); + } - BOOLSPFA () $ { $ for(inti=s;i<=t;i++) {v[i]=0;d [i]=inf;} -Q.push (s);d [s]=0; v[s]=1; - while(!q.empty ()) the { - intX=q.front (); Q.pop (); v[x]=0;Wuyi for(intI=head[x],y;i;i=e[i].next) the if(e[i].v&&d[x]+e[i].c<d[y=E[i].go]) - { WuD[Y]=D[X]+E[I].C; from[y]=i; - if(!v[y]) {v[y]=1; Q.push (y);} About } $ } - returnd[t]!=inf; - } - voidMCF () A { + while(SPFA ()) the { - inttmp=inf; $ for(intI= from[t];i;i= from[E[i]. from]) tmp=min (tmp,e[i].v); themincost+=d[t]*tmp; the for(intI= from[t];i;i= from[E[i]. from]) {e[i].v-=tmp;e[i^1].v+=tmp;} the } the } - intMain () in { theFreopen ("Input.txt","R", stdin); theFreopen ("output.txt","W", stdout); AboutN=read (); M=read (); s=0; t=n+m+1; theFor1 (I,n) A[i]=read (), B[i]=read (), C[i]=read (), d[i]=read (); the For1 (i,m) the { + intX=read (), Y=read (); ss[x]++;ss[y]++; -Insert (S,i+n,1,0); theInsert (I+n,x,1,0);BayiInsert (I+n,y,1,0); the } theFor1 (i,n) b[i]+=Ss[i]; - For1 (i,n) - { the intx=a[i],y=B[i]; the For1 (j,ss[i]) the { theInsert (I,t,1,2*c[i]*x-2*d[i]*y+c[i]+d[i]); -x++;y--; the } the } the intans=0;94For1 (i,n) ans+=c[i]*a[i]*a[i]+d[i]*b[i]*B[i]; the MCF (); theprintf"%d\n", ans+mincost); the return 0;98}
View Code
1449: [JSOI2009] Team earnings time limit:5 Sec Memory limit:64 MB
submit:411 solved:225
[Submit] [Status] Description Input Output An integer that represents the minimum value of the sum of the benefits of all teams in the league. Sample Input3 3
1 0 2 1
1 1 10 1
0 1 3 3
1 2
2 3
3 1
Sample Output43
HINT
Source
BZOJ1449: [JSOI2009] Team Benefits