【最大流EK】

来源:互联网 发布:mysql 命令行建数据库 编辑:程序博客网 时间:2024/06/01 10:34



int EK(int s,int t){queue<int> q;int ans = 0;while(true){memset(a,0,sizeof(a));a[s] = INF;q.push(s);while(!q.empty()){int u = q.front();q.pop();for(int v=0;v<=t;v++){if(!a[v] && c[u][v] > f[u][v]){a[v] = min(a[u],c[u][v]-f[u][v]);pre[v] = u;q.push(v);}}}if(a[t] == 0) break;for(int u=t;u!=s;u=pre[u]){f[pre[u]][u] += a[t];f[u][pre[u]] -= a[t];}ans += a[t];}return ans;}


0 0
原创粉丝点击