hdu 4280(最大流ISAP)

http://acm.hdu.edu.cn/showproblem.php?pid=4280

模板题裸的最大流,n和m较大,时间卡的紧,要用堆栈加bfs优化

#include 
#include 
#include 
#include 
#include 
using namespace std;

const int maxn=100000+10;
const int inf=0x3f3f3f3f;
int n,m;
struct point{
    int x,y;
}p[maxn];
struct Edge{
    int to,next,cap,flow;
}edge[maxn<<1];
int to1;
int head[maxn],gap[maxn],dep[maxn],cur[maxn];
void init(){
    to1=0;
    memset(head,-1,sizeof(head));
}
void addedge(int u,int v,int w,int rw=0){
    edge[to1].to=v;
    edge[to1].cap=w;
    edge[to1].next=head[u];
    edge[to1].flow=0;
    head[u]=to1++;
    edge[to1].to=u;
    edge[to1].cap=rw;
    edge[to1].next=head[v];
    edge[to1].flow=0;
    head[v]=to1++;
}
int Q[maxn];
void bfs(int s,int t){
    memset(dep,-1,sizeof(dep));
    memset(gap,0,sizeof(gap));
    gap[0]=1;
    int front=0,rear=0;
    dep[t]=0;
    Q[rear++]=t;
    while(front!=rear){
        int u=Q[front++];
        for(int i=head[u];i!=-1;i=edge[i].next){
            int v=edge[i].to;
            if(dep[v]!=-1)continue;
            Q[rear++]=v;
            dep[v]=dep[u]+1;
            gap[dep[v]]++;
        }
    }
}
int S[maxn];
int sap(int s,int t,int N){
    bfs(s,t);
    memcpy(cur,head,sizeof(head));
    int top=0;
    int u=s;
    int ans=0;
    while(dep[s]edge[S[i]].cap-edge[S[i]].flow){
                    Min=edge[S[i]].cap-edge[S[i]].flow;
                    inser=i;
                }
            }
            for(int i=0;ip[i].x){
                left=p[i].x;l=i;
            }
            if(right

 

你可能感兴趣的:(算法)