const int SIZE_V //= 600;
const int SIZE_E //= 600;
typedef int weight_t;
int n,m;
int start //= 1;
int end //= m;
//边的结构
struct edge_t{
int node;
weight_t c;//c为容量
edge_t* next;
edge_t* redge;//指向反向边
}Edge[SIZE_E];
int ECnt;
//图的邻接表
edge_t* V[SIZE_V];
void init(){
ECnt = 0;
//fill(V+1,V+m+1,(edge_t*)0);
MEM(V,0);
}
//生成双向边
void mkEdge(int a,int b,weight_t c){
int t1 = ECnt++;
int t2 = ECnt++;
Edge[t1].node = b;
Edge[t1].c = c;
Edge[t1].next = V[a];
Edge[t1].redge = Edge + t2;
V[a] = Edge + t1;
Edge[t2].node = a;
Edge[t2].c = 0;
Edge[t2].next = V[b];
Edge[t2].redge = Edge + t1;
V[b] = Edge + t2;
}
bool F[SIZE_V];
//u当前节点,f为当前流
int dfs(int u,int current){
if ( u == end ) return current;
F[u] = true;
for(edge_t*p=V[u]; p ;p=p->next){
int v = p->node;
if( F[v] ) continue;
weight_t c = p->c;
if ( c > 0 ){
int t = dfs(v,min(c,current));
if ( 0 == t ) continue;
p->c -= t;
p->redge->c += t;
return t;
}
}
return 0;
}
int solve(){
int ret = 0;
while(1){
MEM(F,0);
//fill(F+1,F+m+1,false);
int t = dfs(start,INT_MAX);
if ( 0 == t ) return ret;
ret += t;
}
}
最大流的Ford-Fulkerson方法初步
最新推荐文章于 2022-03-05 17:39:28 发布