bzoj 1189: [HNOI2007]紧急疏散evacuate 分层图最大流_拆点_二分

bzoj 1189: [HNOI2007]紧急疏散evacuate 分层图最大流_拆点_二分

Code:

#include
#define setIO(s) freopen(s".in","r",stdin) 
#define maxn 100000 
#define inf 100000 
using namespace std;
namespace Dinic{
    struct Edge{
        int from,to,cap;
        Edge(int a=0,int b=0,int c=0):from(a),to(b),cap(c){} 
    }; 
    queueQ;    
    vectoredges; 
    vectorG[maxn]; 
    void add(int u,int v,int c){
        edges.push_back(Edge(u,v,c)); 
        edges.push_back(Edge(v,u,0)); 
        int m=edges.size(); 
        G[u].push_back(m-2); 
        G[v].push_back(m-1); 
    }
    int S,T,vis[maxn],d[maxn],current[maxn]; 
    int BFS(){
        memset(vis,0,sizeof(vis)); 
        vis[S]=1,d[S]=0; Q.push(S);
        while(!Q.empty()){
            int u=Q.front();Q.pop(); 
            for(int sz=G[u].size(),i=0;i0) {
                    vis[r.to]=1,d[r.to]=d[u]+1; 
                    Q.push(r.to); 
                }
            }
        }
        return vis[T]; 
    }
    int dfs(int x,int cur){
        if(x==T) return cur; 
        int flow=0,f; 
        for(int sz=G[x].size(),i=current[x];i0) {
                if(f=dfs(r.to,min(cur,r.cap)))  {
                    flow+=f,cur-=f;   
                    edges[G[x][i]].cap-=f,edges[G[x][i]^1].cap+=f; 
                }
            }
            if(cur==0) break; 
        }   
        return flow;            
    }
    int maxflow(){
        int flow=0; 
        while(BFS()){
            memset(current,0,sizeof(current)); 
            flow+=dfs(S,inf); 
        }
        return flow; 
    }    
    void re(){
        S=T=0; 
        for(int i=0;igate,G[maxn];
int mapp[500][300],n,m,sum; 
bool check(int t){ 
    int id=0; 
    Dinic::re(); 
    Dinic::S=0,Dinic::T=5000;  
    for(int sz=gate.size(),i=0;i=1&&gr[i-1][j]!=1) d[idx(i,j)][idx(i-1,j)]=ck[idx(i,j)][idx(i-1,j)]=1; 
            if(i+1<=n&&gr[i+1][j]!=1) d[idx(i,j)][idx(i+1,j)]=ck[idx(i,j)][idx(i+1,j)]=1; 
            if(j+1<=m&&gr[i][j+1]!=1) d[idx(i,j)][idx(i,j+1)]=ck[idx(i,j)][idx(i,j+1)]=1;
            if(j-1>=1&&gr[i][j-1]!=1) d[idx(i,j)][idx(i,j-1)]=ck[idx(i,j)][idx(i,j-1)]=1; 
        } 
    int tot=n*m; 
    for(int i=1;i<=tot;++i) ck[i][i]=1,d[i][i]=0;             
    for(int k=1;k<=tot;++k)
        for(int i=1;i<=tot;++i) 
            for(int j=1;j<=tot;++j) if(ck[i][k]&&ck[k][j]) ck[i][j]=1;  
    for(int k=1;k<=tot;++k) 
        for(int i=1;i<=tot;++i)
            for(int j=1;j<=tot;++j) if(ck[i][j]) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);   
    for(int i=1;i<=n;++i)  
        for(int j=1;j<=m;++j) 
            if(gr[i][j]==0){
                bool flag=0; 
                for(int sz=gate.size(),t=0;t>1; 
        if(check(mid)) ans=mid,r=mid-1;
        else l=mid+1; 
    } 
    printf("%d",ans); 
    return 0; 
}

  

posted @ 2019-05-18 21:33 EM-LGH 阅读( ...) 评论( ...) 编辑 收藏

你可能感兴趣的:(bzoj 1189: [HNOI2007]紧急疏散evacuate 分层图最大流_拆点_二分)