BZOJ-2540 循环格

题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3171

一道裸的费用流,在windows下莫名死循环了N久,换到Linux下就A了。。。

代码:

03087bf40ad162d97d92c31813dfa9ec8a13cdb2.jpg.png
#include 
#include 
#include 
 
using namespace std;
 
#define MAXN 1010
#define inf 0x7fffffff
 
struct edge {
        int t,f,c;
        edge *pair,*next;
        edge () {
               pair=next=NULL;
        }
} *head[MAXN];
 
void Add(int s,int t,int f,int c) {
        edge *p=new(edge);
        p->t=t;
        p->f=f;
        p->c=c;
        p->next=head[s];
        head[s]=p;
}
 
void AddEdge(int s,int t,int f,int c) {
        Add(s,t,f,c);
        Add(t,s,0,-c);
        head[s]->pair=head[t];
        head[t]->pair=head[s];
}
 
int V=0,S,T;
int n,m;
 
int dist[MAXN],slack[MAXN];
int cost=0,maxflow=0;
bool f[MAXN];
 
int aug(int v,int flow) {
        if (v==T) {
               cost+=flow*(dist[S]-dist[T]);
               return flow;
        }
        f[v]=false;
        int rec=0;
        for (edge *p=head[v];p;p=p->next) {
               if (p->f&&f[p->t]) {
                       if (dist[v]==dist[p->t]+p->c) {
                               int ret=aug(p->t,min(flow-rec,p->f));
                               p->f-=ret,p->pair->f+=ret;
                               if ((rec+=ret)==flow) return flow;
                       } else slack[p->t]=min(slack[p->t],dist[p->t]-dist[v]+p->c);
               }
        }
        return rec;
}
 
bool relabel() {
        int delta=inf;
        for (int i=0;i++

你可能感兴趣的:(BZOJ-2540 循环格)