Network Flow Thematic Solutions ($by\ xzz zz)$

Keywords: PHP

[] Logue $P4126\ [AHOI2009] $minimum cut

$umm$

[X]$CF311E\ Biologist$

Minimum cut,sense $jio$Stiff,,,?I don't want to write it in detail. $QwQ$

#include<bits/stdc++.h>
using namespace std;
#define il inline
#define gc getchar()
#define int long long
#define t(i) edge[i].to
#define n(i) edge[i].nxt
#define w(i) edge[i].wei
#define ri register int
#define rb register bool
#define rc register char
#define rp(i,x,y) for(ri i=x;i<=y;++i)
#define e(i,x) for(ri i=head[x];~i;i=n(i))

const int N=30000+10,inf=1e9;
int n,m,S,T,ed_cnt=-1,head[N],as,cur[N],dep[N],g,a[N];
struct ed{int to,nxt,wei;}edge[N<<2];

il int read()
{
    rc ch=gc;ri x=0;rb y=1;
    while(ch!='-' && (ch>'9' || ch<'0'))ch=gc;
    if(ch=='-')ch=gc,y=0;
    while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=gc;
    return y?x:-x;
}
il void ad(ri x,ri y,ri z){edge[++ed_cnt]=(ed){x,head[y],z};head[y]=ed_cnt;edge[++ed_cnt]=(ed){y,head[x],0};head[x]=ed_cnt;}
il bool bfs()
{
    queue<int>Q;Q.push(S);memset(dep,0,sizeof(dep));dep[S]=1;
    while(!Q.empty()){ri nw=Q.front();Q.pop();e(i,nw)if(w(i) && !dep[t(i)])dep[t(i)]=dep[nw]+1,Q.push(t(i));}
    return dep[T];
}
il int dfs(ri nw,ri flow)
{
    if(nw==T || !flow)return flow;ri ret=0;
    for(ri &i=cur[nw];~i;i=n(i))
        if(w(i) && dep[t(i)]==dep[nw]+1){ri tmp=dfs(t(i),min(flow,w(i)));ret+=tmp,w(i)-=tmp;w(i^1)+=tmp,flow-=tmp;}
    return ret;
}
il int dinic(){ri ret=0;while(bfs()){rp(i,S,T)cur[i]=head[i];while(int d=dfs(S,inf))ret+=d;}return ret;}

 main()
{
//    freopen("331e.in","r",stdin);freopen("331e.out","w",stdout);
    n=read();m=read();g=read();rp(i,1,n)a[i]=read();S=0;T=n+m+1;memset(head,-1,sizeof(head));
    rp(i,1,n){ri tmp=read();if(a[i])ad(T,i,0),ad(i,S,tmp);else ad(T,i,tmp),ad(i,S,0);}
    rp(i,1,m)
    {
        ri tmp=read(),w=read(),num=read();as+=w;
        rp(j,1,num){ri x=read();tmp?ad(x,i+n,inf):ad(i+n,x,inf);}
        w+=read()*g;tmp?ad(i+n,S,w):ad(T,i+n,w);
    }
    printf("%lld\n",as-dinic());
    return 0;
}

[] Luogu $P3227\ [HNOI2013] $cut cake

[] Luogu $P2046\ [NOI2010] $altitude

[] Logue $P3308\ [SDOI2014]LIS$

[] Luogu $P3756\ [CQOI2017] $old $C $box

[] $BZOJ3232 $enclosure game

[] rogue $P3324\ [SDOI2015] $Star Wars

[] Luogu $P2570\ [ZJOI2010] $greedy mouse

[] $LOJ6045 $[Yali training $2017\ Day8 $] price

[] Luogu $P2805\ [NOI2009] $plant vs. zombie

[] Luogu $P49 [six provinces joint examination 2017] sushi restaurant

[] Valley $P53 80 people around the world

[] Luogu $P4043\ [AHOI2014/JSOI2014] $regional plot

[] Luogu $P11 soldiers occupy

[] Luogu $P5029\ T'ill\ It's\ Over$

[ ]$BZOJ3218\ A+B\ Problem$

[] $WC07 scissors and stone cloth

[] Logue $P3877\ [TJOI2010] $cleaning room

[] Valley $P03 infinite ring

[] Logan $P4068\ [SDOI2016] $digital pairing

[] Luogu $P3980\ [NOI2008] $Volunteer Recruitment

[ ]$CF708D\ Incorrect\ Flow$

[] Logue $P4486\ [BJWC2018]Kakuro$

[] Luogu $P2053\ [SCOI2007] $repair

[] Luogu $P2053\ [NOI2012] $Meiji Festival

[] Luogu $P82 [joint examination of eight provinces 2018] split

Posted by muinej on Tue, 15 Oct 2019 10:13:02 -0700