首页 技术 正文
技术 2022年11月19日
0 收藏 716 点赞 2,785 浏览 1270 个字

ISAP求最大流,敲了一发板子,无压行,教程略去。转载请随意。

 #include <cstdio> #include <cstring> #include <algorithm> #include <vector> using namespace std; ; const int inf = 0x33333333; struct edge {     int to, rev, cap; }; int n; vector<edge> G[maxn]; void add_edge(int u, int v, int cap) {     G[u].push_back((edge){v, (int)G[v].size(), cap});     G[v].push_back((edge){u, (, }); } int isap(int s, int t) {     //init     static int h[maxn];    //距离标号     static int cnt[maxn];  //距离标号计数     static int cur[maxn];  //当前弧     static int pv[maxn];   //上一个顶点     static int pe[maxn];   //上一条弧     memset(h, , sizeof h);     memset(cnt, , sizeof cnt);     cnt[] = n;     memset(cur, , sizeof cur);     //solve     int u = s;     ;     while(true) {         if(u == t) {             //augment             int newflow = inf;             for(int x = t; x != s; x = pv[x]) {                 edge &e = G[pv[x]][pe[x]];                 newflow = min(newflow, e.cap);             }             flow += newflow;             for(int x = t; x != s; x = pv[x]) {                 edge &e = G[pv[x]][pe[x]];                 e.cap -= newflow;                 G[x][e.rev].cap += newflow;             }             u = s;         }         bool did = false;         for(int &i = cur[u]; i < (int)G[u].size(); ++i) {             edge &e = G[u][i];              && h[u] == h[e.to] + ) {                 //advance                 did = true;                 pv[e.to] = u;                 pe[e.to] = i;                 u = e.to;                 break;             }         }         if(!did) {             //retreat             ;             ; i < (int)G[u].size(); ++i) {                 edge &e = G[u][i];                 ) {                     newh = min(newh, h[e.to] + );                 }             }             ) {                 //gap                 break;             }             ++cnt[h[u] = newh];             if(u != s) {                 u = pv[u];             }         }     }     return flow; } int main(void) {     int m, source, sink;     scanf("%d%d%d%d", &n, &m, &source, &sink), --source, --sink;     ; i < m; ++i) {         int from, to, cap;         scanf("%d%d%d", &from, &to, &cap), --from, --to;         add_edge(from, to, cap);     }     printf("%d\n", isap(source, sink));     ; }
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,023
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,513
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,360
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,143
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,774
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,852