1#include <cstdio>2#include <iostream>3#include <cstring>4 #defineM 100005 #defineINF 21390621436 using namespacestd;7 intCnt=1, n,m,t,d[m],q[2*m],f[m],head[m],next[Ten*m],u[Ten*m],v[Ten*m],w[Ten*m],fro[Ten*M],fr[m];8 intmp[ -];9 Long Longans;Ten voidJia1 (intA1,intA2,intA3,intA4) One { Acnt++; -next[cnt]=HEAD[A1]; -head[a1]=CNT; thefro[cnt]=A1; -u[cnt]=A2; -v[cnt]=A3; -w[cnt]=A4; + } - voidJiaintA1,intA2,intA3,intA4) + { A jia1 (A1,A2,A3,A4); atJia1 (A2,A1,0,-A4); - return; - } - BOOLSPFA () - { -memset (D,127,sizeof(int) * (t+1)); ind[0]=0; -f[0]=1; toq[1]=0; + intH=0, t=1; - for(;h<t;) the { *h++; $ intp=Q[h];Panax Notoginsengf[p]=0; - for(intI=head[p];i;i=Next[i]) the if(v[i]&&d[u[i]]>d[p]+W[i]) + { Ad[u[i]]=d[p]+W[i]; thefr[u[i]]=i; + if(!F[u[i]]) - { $f[u[i]]=1; $t++; -q[t]=U[i]; - } the } - }Wuyi if(d[t]!=inf) the return 1; - return 0; Wu } - voidMCF () About { $ intmx=inf; - for(intI=fr[t];i;i=Fr[fro[i]]) -mx=min (mx,v[i]); - for(intI=fr[t];i;i=Fr[fro[i]]) A { +v[i]-=MX; thev[i^1]+=MX; -ans+=mx*W[i]; $ } the return; the } the intMain () the { -scanf"%d%d",&n,&m); int=n+m+1; the for(intI=1; i<=m;i++) the { About intA1; thescanf"%d",&A1); theJia (N+I,T,A1,0); the } + for(intI=1; i<=n;i++) - for(intj=1; j<=m;j++) the {Bayi intA1; thescanf"%d",&A1); the if(A1) -Jia (I,n+j,inf,0); - } the for(intI=1; i<=n;i++) the { the intsi; thescanf"%d",&si); - for(intj=1; j<=si;j++) thescanf"%d",&mp[j]); themp[si+1]=inf; the for(intj=1; j<=si+1; j + +)94 { the intA1; thescanf"%d",&A1); theJia0, i,mp[j]-mp[j-1],a1);98 } About } - for(; SPFA ();)101 MCF ();102printf"%lld\n", ans);103 return 0;104}
Split run cost stream by Segment function.
Bzoj 2245: [SDOI2011] organization of work