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

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

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. Ubuntu安装google chrome过程

    Ubuntu安装google chrome过程: # wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd6 ...

  2. jquery 选项卡实现

    HTML文件 $(function(){ var $div_li =$("div.tab_menu ul li"); $div_li.click(function(){ $(thi ...

  3. MLlib-分类与回归

    MLlib支持二分类,多酚类和回归分析的多种方法,具体如下: 问题类别 支持方法 二分类 线性支持向量机, 逻辑回归,决策树,朴素贝叶斯 多分类 决策树,朴素贝叶斯 回归 线性最小二乘,Lasso,r ...

  4. 使用Ajax.ActionLink时,点击对应的按钮会重新加载一个页面,而不是在当前页面的指定模块加载

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. 使用飞信api接口实现短信发送(只能发送好友)

    找了很久才找到一个能用的飞信API接口(http://quanapi.sinaapp.com/fetion.php?u=飞信登录手机号&p=飞信登录密码&to=接收飞信的手机号& ...

  6. Spark笔记-treeReduce、reduce、reduceByKey

    参考资料: http://stackoverflow.com/questions/32281417/understadning-treereduce-in-spark http://stackover ...

  7. UI基础 - UITabBarController

    self.window = [[UIWindow alloc] init]; self.window.frame = [UIScreen mainScreen].bounds; oneViewCont ...

  8. Maven内置隐式变量

    Maven提供了三个隐式的变量可以用来访问环境变量,POM信息,和Maven Settings env env变量,暴露了你操作系统或者shell的环境变量.便 如在Maven POM中一个对${en ...

  9. Android 判断当前网络连接类型

    实际应用开发时,如果存在需要用户获取大量数据的情况,最好是先判断下网络类型,提示用户当前的网络类型,是否需要连接Wifi,etc.(手机流量太贵啦,当然土豪是无视这玩意的, (/ □ \)). 定义网 ...

  10. Keil C51里面lib文件生成和调用方法

    一.包含关系 LCD1602.C里面包含LCD1602.H LCD1602.H的文件格式 二.设置生成lib文件 三.Lib文件调用 添加lib文件对话框 添加后的lib文件 呵呵^_^,这样就可以删 ...