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

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

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. 跟我学android-android常用布局介绍

    在上一章我们曾经谈到,Android平台的界面 是使用XML的方式设计的,然后在上一章我们只做了一个简单的界面,在这章,我们将介绍如何使用常用的控件设计实用的界面. Android中的视图都是继承Vi ...

  2. 【USACO 3.2.4】饲料调配

    [描述] 农夫约翰从来只用调配得最好的饲料来喂他的奶牛.饲料用三种原料调配成:大麦,燕麦和小麦.他知道自己的饲料精确的配比,在市场上是买不到这样的饲料的.他只好购买其他三种混合饲料(同样都由三种麦子组 ...

  3. Unable to locate package错误解决办法

    新装了VMWare Player,结果装上Ubuntu12.04后安装软件都提示:Unable to locate package错误,解决方法非常简单,终端输入以下命令即可: sudo apt-ge ...

  4. Phalcon 的 bootstrap.php 自动加载完成;非常人性化的设计

    <?php /** * Bootstraps the application */ use Phalcon\DI\FactoryDefault as PhDi, Phalcon\Config a ...

  5. hdu 4548 第六周H题(美素数)

    第六周H题 - 数论,晒素数 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   De ...

  6. 转:mysql5.6.12 for Linux安装

    原文链接:http://mmicky.blog.163.com/blog/static/1502901542013635317349/ 1:上www.mysql.org下载64位版本mysql5.6. ...

  7. java指纹识别+谷歌图片识别技术

    http://www.icodeguru.com/3/2451.html http://valseonline.org/thread-124-1-1.html

  8. mysql 主从 配置和同步管理

    首先呢,需要有两个mysql服务器.如果做测试的话可以在同一台机器上装两个mysql服务程序,注意要两个运行程序的端口不能一样.我用的是一个是默认的3306,从服务器用的是3307端口. 在主服务创建 ...

  9. Codeforces Round #312 (Div. 2) B.Amr and The Large Array

    Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller. ...

  10. sql server 的ANSI_NULLS设置

    当 SET ANSI_NULLS 为 ON 时,表示SQL语句遵循SQL-92标准.当 SET ANSI_NULLS 为 OFF 时,表示不遵从 SQL-92 标准. SQL-92 标准要求对空值(N ...