dijkstra优化的最小费用最大流

const int inf = 0x3f3f3f3f;
int tol,head[4010];
struct edge{
    int to,next,cap,flow,cost;
}es[8000010];
void init(){
    tol = 0; memset( head , -1 , sizeof(head) );
}
void addedge( int u , int v , int cap , int cost ){
    es[tol].to = v;
    es[tol].cap = cap;
    es[tol].cost = cost;
    es[tol].flow = 0;
    es[tol].next = head[u];
    head[u] = tol++;
    es[tol].to = u;
    es[tol].cap = 0;
    es[tol].cost = -cost;
    es[tol].flow = 0;
    es[tol].next = head[v];
    head[v] = tol++;
}
typedef pair p; int dis[4010],h[4010],pre_node[4010],pre_edge[4010];

void MCMF( int s , int t , int n ){
    int flow = 0;
    int cost = 0;
    for( int i=0 ; i,greater

>Q; dis[s] = 0; Q.push(make_pair(0,s)); while( !Q.empty() ){ p now = Q.top(); Q.pop(); int u = now.second; if( dis[u]

 

你可能感兴趣的:(图论模板)