题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3549

题意:求1到n的最大流

题解:模版题,直接上Claris的ISAP,效率是一般dfs的十倍,ORZ Claris!!!

 #include<cstdio>
#include<algorithm>
#define F(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int N=,inf=~0U>>,M=;
struct edge{int t,f;edge*nxt,*pair;}*g[N],*d[N],pool[M],*cur=pool;
struct ISAP{
int n,m,i,S,T,h[N],gap[N],maxflow;
void init(int ss,int tt){for(S=ss,T=tt,cur=pool,i=;i<=T;i++)g[i]=d[i]=NULL,h[i]=gap[i]=;}
void add(int s,int t,int f){
edge*p=cur++;p->t=t,p->f=f,p->nxt=g[s],g[s]=p;
p=cur++,p->t=s,p->f=,p->nxt=g[t],g[t]=p;
g[s]->pair=g[t],g[t]->pair=g[s];
}
int sap(int v,int flow){
if(v==T)return flow;
int rec=;
for(edge*p=d[v];p;p=p->nxt)if(h[v]==h[p->t]+&&p->f){
int ret=sap(p->t,min(flow-rec,p->f));
p->f-=ret;p->pair->f+=ret;d[v]=p;
if((rec+=ret)==flow)return flow;
}
if(!(--gap[h[v]]))h[S]=T;
gap[++h[v]]++;d[v]=g[v];
return rec;
}
int get_ans(){
for(gap[maxflow=]=T,i=;i<=T;i++)d[i]=g[i];
while(h[S]<T)maxflow+=sap(S,inf);
return maxflow;
}
}G; int main(){
int t,n,m,x,y,c,ic=;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);//点,边
G.init(,n);
F(i,,m)scanf("%d%d%d",&x,&y,&c),G.add(x,y,c);
printf("Case %d: %d\n",ic++,G.get_ans());
}
}

hdu_3549_Flow Problem(最大流)的更多相关文章

  1. Flow Problem(最大流模板)

    Flow Problem Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Tota ...

  2. UVA 10779 Collectors Problem(最大流)

    这个题是很难往网络流上面构思的... 从s向每个物品增加容量为Bob拥有数的弧,然后从每个物品向t增加容量为1的弧(代表种类个数).这时候跑最大流的话,得到的肯定是Bob拥有的初始种类数.那么交换后的 ...

  3. hdu 3549 Flow Problem (最大流)

    裸最大流,做模板用 m条边,n个点,求最大流 #include <iostream> #include <cstdio> #include <cstring> #i ...

  4. hdu 3549 Flow Problem 最大流 Dinic

    题目链接 题意 裸的最大流. 学习参考 http://www.cnblogs.com/SYCstudio/p/7260613.html Code #include <bits/stdc++.h& ...

  5. hdu 4975 A simple Gaussian elimination problem 最大流+找环

    原题链接 http://acm.hdu.edu.cn/showproblem.php?pid=4975 这是一道很裸的最大流,将每个点(i,j)看作是从Ri向Cj的一条容量为9的边,从源点除法连接每个 ...

  6. HDU-3549Flow Problem 最大流模板题

    传送门 这里是Ford-Fulkerson写的最大流模板 #include <iostream> #include <cstdio> #include <algorith ...

  7. [hdu3549]Flow Problem(最大流模板题)

    解题关键:使用的挑战程序设计竞赛上的模板,第一道网络流题目,效率比较低,且用不习惯的vector来建图. 看到网上其他人说此题有重边,需要注意下,此问题只在邻接矩阵建图时会出问题,邻接表不会存在的,也 ...

  8. hdu - 3549 Flow Problem (最大流模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=3549 Ford-Fulkerson算法. #include <iostream> #include ...

  9. HDU3549:Flow Problem(最大流入门EK)

    #include <stdio.h> #include <string.h> #include <stdlib.h> #include <queue> ...

随机推荐

  1. oc 是否允许远程通知

    UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSett ...

  2. 灰色关联度Matlab代码

    load x.txt %把原始数据存放在纯文本文件x.txt中,其中把数据的"替换替换成. for i=1:40x(i,:)=x(i,:)/x(i,1); %标准化数据end data=x; ...

  3. Find and run the whalesay image

    Find and run the whalesay image People all over the world create Docker images. You can find these i ...

  4. Oracle Day05 集合与数据处理

    1.集合 --集合操作: 并集.交集.差. select deptno,job,sum(sal) from emp group by deptno,job union select deptno,to ...

  5. radiobutton以及checkbox背景图片拉伸变形的问题

    设置RadioButton的text属性,只需要有这个属性就可以(设置“”内容就行),然后再添加textsize属性,将字体大小属性值设置为比较小,我设置为2sp.运行后我们会发现图片变形问题不复存在 ...

  6. VBS基础篇 - VBScript过程

    VBS基础篇 - VBScript过程   在 VBScript 中,过程被分为两类:Sub 过程和 Function 过程. Sub过程 Sub 过程是包含在 Sub 和 End Sub 语句之间的 ...

  7. 关于stringWithFormat: - 两段NSString如何合成一段

    http://blog.sina.com.cn/s/blog_6b1e4a0601019pib.html str = [NSString stringWithFormat:@"%@,%@&q ...

  8. eclipse如何快速抽取样式(style)或者include

    在视图模式上选中要抽取的模块,然后点击右键就可以抽取了

  9. Ckeditor配置

    配置参考文档,主要将ckeditor中的(adapters.images.lang.plugins.skins.themes.ckeditor.js.config.js.contents.css)解压 ...

  10. rs.Open sql,conn,0,2,1

    例子:rs.Open sql,conn,0,2,1 CursorType = 0,默认值,打开仅向前类型游标.LockType = 2, 开放式锁定Options = 1, 指示 ADO 生成 SQL ...