#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
const int MAXN=;
const int INF=0x7fffffff;
int n,m;//n:edges,m:points
struct node
{
int to,pos,cap;
};
vector<node> E[MAXN];
int vis[MAXN]; void addedge(int u,int v,int w)
{
node x;
x.to=v; x.pos=E[v].size(); x.cap=w;
E[u].push_back(x);
x.to=u; x.pos=E[u].size()-; x.cap=;
E[v].push_back(x);
} int dfs(int s,int t,int f)
{
int ret=;
if (s==t) return f;
vis[s]=;//不要忘记这里要设置为访问过
for (int i=;i<E[s].size();i++)
{
node &tmp=E[s][i];
if (vis[tmp.to]== && tmp.cap>)
{
int delta=dfs(tmp.to,t,min(tmp.cap,f));
if (delta>)
{
ret+=delta;
tmp.cap-=delta;
E[tmp.to][tmp.pos].cap+=delta;
f-=delta;
}
}
}
return ret;
} int maxflow(int u,int v)
{
int flow=;
for (;;)
{
memset(vis,,sizeof(vis));
int f=dfs(u,v,INF);
if (f==) return flow;
else flow+=f;
}
} int main()
{
while(~scanf("%d%d",&n,&m))
{
memset(E,,sizeof(E));
for (int i=;i<n;i++)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
addedge(x,y,z);
}
cout<<maxflow(,m)<<endl;
}
return ;
}

2016/3/6更正:建立一个ret,每次递归不是找到一条增广路径就返回的..之前写的和FordFulkerson效率超不多orz

【最大流Dinic模板】HDU1532&POJ1273-Drainage Ditches(16/3/6更正)的更多相关文章

  1. poj1273 Drainage Ditches Dinic最大流

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 76000   Accepted: 2953 ...

  2. POJ1273:Drainage Ditches(最大流入门 EK,dinic算法)

    http://poj.org/problem?id=1273 Description Every time it rains on Farmer John's fields, a pond forms ...

  3. POJ-1273 Drainage Ditches 最大流Dinic

    Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 65146 Accepted: 25112 De ...

  4. 2018.07.06 POJ1273 Drainage Ditches(最大流)

    Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Description Every time it rains on Farmer J ...

  5. poj-1273 Drainage Ditches(最大流基础题)

    题目链接: Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 67475   Accepted ...

  6. 【网络流】POJ1273 Drainage Ditches

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 78671   Accepted: 3068 ...

  7. poj1273 Drainage Ditches

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 68414   Accepted: 2648 ...

  8. POJ1273 Drainage Ditches (网络流)

                                                             Drainage Ditches Time Limit: 1000MS   Memor ...

  9. (网络流 模板 Edmonds-Karp)Drainage Ditches --POJ --1273

    链接: http://poj.org/problem?id=1273 Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total ...

  10. poj1273 Drainage Ditches (最大流模板)

    http://poj.org/problem?id=1273 Dinic算法 这是一道最大流的经典题 最大流尽量应该用边表,优于邻接矩阵(所以我写了邻接矩阵版的之后又写了个边表) 用了新学的Dinic ...

随机推荐

  1. Sberbank Russian Housing Market比赛总结

    第一次真正意义上参加kaggle比赛,都是工作之余看看别人的kernel,然后整理整理自己的分析代码. 总体来说,本次比赛对我而言更像一个入门比赛,更多的是走走kaggle比赛的整个流程,看看高手们都 ...

  2. Java多线程学习(六)Lock锁的使用

    系列文章传送门: Java多线程学习(二)synchronized关键字(1) Java多线程学习(二)synchronized关键字(2) Java多线程学习(三)volatile关键字 Java多 ...

  3. linux 3389连接工具Rdesktop

    简单使用 工作机换成战斗机了,改用ubuntu,原来的windows7上东西笔记多,还不想重装.用rdesktop来远程连接windows: sudo apt-get install rdesktop ...

  4. Yii 1.1.17 五、分页类、关联模型、权限验证与默认页面跳转

    一.分页类使用 1.在控制器中 // 实例化 $criteria = new CDbCriteria(); $articleModel = Article::model(); // 分页 $total ...

  5. python基础===成员访问__len__()和__getitem__()

    class A: def __init__(self,*args): self.name = arg pass def __len__(self): return len(self.name) a = ...

  6. 1006. Team Rankings

    Description It's preseason and the local newspaper wants to publish a preseason ranking of the teams ...

  7. 在Caffe中使用 DIGITS(Deep Learning GPU Training System)自定义Python层

    注意:包含Python层的网络只支持单个GPU训练!!!!! Caffe 使得我们有了使用Python自定义层的能力,而不是通常的C++/CUDA.这是一个非常有用的特性,但它的文档记录不足,难以正确 ...

  8. maven使用备忘

    maven的所有功能本质上都是通过插件来实现的所有的功能.archetype插件就是根据项目类型创建项目的插件.执行archetype:generate命令就会list一系列的项目类型,可以选择一个合 ...

  9. python 基础 习题

    1.执行 Python 脚本的两种方式2.简述位.字节的关系 1Byte = 8bits 3.简述 ascii.unicode.utf-8.gbk 的关系 都是字符集,unicode兼容其他3种字符集 ...

  10. hihocoder 1178 : 计数

    #1178 : 计数 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Rowdark是一个邪恶的魔法师.在他阅读大巫术师Lich的传记时,他发现一类黑魔法来召唤远古生物, ...