因为坑了无数次队友 要开始学习网络流了,先从基础的开始,嗯~

这道题是最大流的模板题,用来测试模板好啦~

Edmonds_Karp模板 with 前向星

时间复杂度o(V*E^2)

 #include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<queue>
#define eps 0.000001
#define MAXN 20
#define MAXM 2005
#define INF (1<<30)
using namespace std;
int i,j,k,n,m,x,y,T,head[MAXN],num,w,pre[MAXN],lin[MAXN];
struct edgenode
{
int to,next,w;
} map[MAXM]; void add_edge(int id,int x,int y,int w)
{
map[id].to=y;
map[id].w=w;
map[id].next=head[x];
head[x]=id;
} bool bfs(int s,int t)
{
int u,v;
queue <int> q;
memset(pre,-,sizeof(pre));
pre[s]=s;
q.push(s);
while(!q.empty())
{
u=q.front();
q.pop();
for(int i=head[u];i!=-;i=map[i].next)
{
v=map[i].to;
if(pre[v]==-&&map[i].w>)
{
pre[v]=u;
lin[v]=i;
if (v==t) return true;
q.push(v);
}
}
}
return false;
} int Edmonds_Karp(int s,int t)
{
int flow=,d,i;
while(bfs(s,t))
{
d=INF;
for(i=t;i!=s;i=pre[i])
d=min(d,map[lin[i]].w);
for(i=t;i!=s;i=pre[i])
{
map[lin[i]].w-=d;
map[lin[i]^].w+=d;
}
flow+=d;
}
return flow;
} void init()
{
memset(head,-,sizeof(head));
scanf("%d%d",&n,&m);
num=;
for (i=;i<m;i++)
{
scanf("%d%d%d",&x,&y,&w);
add_edge(i*,x,y,w);
add_edge(i*+,y,x,);
}
} int main()
{
scanf("%d",&T);
for (int cas=;cas<=T;cas++)
{
init();
printf("Case %d: %d\n",cas,Edmonds_Karp(,n));
}
}

最大流的优化还有dinic和isap

dinic传送:dinic

【网络流#1】hdu 3549 - 最大流模板题的更多相关文章

  1. HDU 1532 最大流模板题

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1532 最近在学网络流,学的还不好,先不写理解了,先放模板... 我觉得写得不错的博客:http://blo ...

  2. 【网络流#2】hdu 1533 - 最小费用最大流模板题

    最小费用最大流,即MCMF(Minimum Cost Maximum Flow)问题 嗯~第一次写费用流题... 这道就是费用流的模板题,找不到更裸的题了 建图:每个m(Man)作为源点,每个H(Ho ...

  3. hdu 1532 Drainage Ditches(最大流模板题)

    Drainage Ditches Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. HDU-3549 最大流模板题

    1.HDU-3549   Flow Problem 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=3549 3.总结:模板题,参考了 http://ww ...

  5. POJ 1273 - Drainage Ditches - [最大流模板题] - [EK算法模板][Dinic算法模板 - 邻接表型]

    题目链接:http://poj.org/problem?id=1273 Time Limit: 1000MS Memory Limit: 10000K Description Every time i ...

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

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

  7. HDU 2222 AC自动机模板题

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=2222 AC自动机模板题 我现在对AC自动机的理解还一般,就贴一下我参考学习的两篇博客的链接: http: ...

  8. HDU 1251 Trie树模板题

    1.HDU 1251 统计难题  Trie树模板题,或者map 2.总结:用C++过了,G++就爆内存.. 题意:查找给定前缀的单词数量. #include<iostream> #incl ...

  9. HDU 3065 (AC自动机模板题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3065 题目大意:多个模式串,范围是大写字母.匹配串的字符范围是(0~127).问匹配串中含有哪几种模 ...

随机推荐

  1. c++面试(二)

    1.宏参数的连接 #define CONS(a,b) (int)(a##e##b) CONS(2,3) =>2e3 =2000 2.const int b=10; int c=20; const ...

  2. win7 该任务映像已损坏或一篡改

    首先找到任务计划程序快捷方式的位置,我的是win7系统,是在:控制面板-->管理工具-->任务计划程序 打开任务计划程序出现了下面的异常提示: 出现了这个异常之后,创建任务.创建基本任务菜 ...

  3. python运维开发之第十一天(RabbitMQ,redis)

    一.RabbitMQ python的Queue与RabbitMQ之间的理解: python的进程或线程Queue只能python自己用.RabbitMQ队列多个应用之间共享队列,互相通信. 1.简单的 ...

  4. uva 725 Division(除法)暴力法!

    uva 725  Division(除法) A - 暴力求解 Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & ...

  5. android 模拟微信消息 OnItemClickListener()方法 [3]

    在 http://www.cnblogs.com/Seven-cjy/p/6101555.html 是基础上修改 MainActivity.java /winxinmff/src/com/exampl ...

  6. Black Box

    http://poj.org/problem?id=1442 #include<cstdio> #include<algorithm> #include<queue> ...

  7. poj 2777Count Color

    http://poj.org/problem?id=2777 注意:a可能比b大 #include <cstdio> #include <cstring> #include & ...

  8. poj 1573Robot Motion

    http://poj.org/problem?id=1573 #include<cstdio> #include<cstring> #include<algorithm& ...

  9. 【转】(DT系列六)devicetree中数据和 struct device有什么关系

    原文网址:http://www.cnblogs.com/biglucky/p/4057499.html devicetree中数据和structdevice有什么关系 总体来说,devicetree与 ...

  10. 服务器端javascript——Rhino和Node

    Node: Node是v8 javasript解析器的一个特别版本,侧重于异步I/O,网络和HTTP 入门见:http://www.cnblogs.com/wishyouhappy/p/3647037 ...