最大流Sap模板

int dfs(int u,int augu){
    int augv=0,v,delta,mind= n-1;
    if(u==T)
        return augu;
    for(v=S;v<=T;v++)
        if(cap[u][v]>0){
            if(dist[u]==dist[v]+1){
                delta=min(augu-augv,cap[u][v]);
                delta=dfs(v,delta);
                cap[u][v]-=delta;
                cap[v][u]+=delta;
                augv+=delta;
                if(augv==augu)
                    return augv;
                if(dist[S]>=n)
                    return augv;
            }
            mind=min(mind,dist[v]);
        }
    if(!augv){
        vd[dist[u]]--;
        if(!vd[dist[u]])
            dist[S]=n;
        dist[u]=mind+1;
        vd[dist[u]]++;
    }
    return augv;
}
void sap(){
    n=T+1;
    vd[0]=n;
    while(dist[S]<n)
        flow+=dfs(S,INF);
}
posted @ 2015-08-26 20:18  outer_form  阅读(99)  评论(0编辑  收藏  举报