【最大流Dinic模板】HDU1532&POJ1273-Drainage Ditches(16/3/6更正)
#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更正)的更多相关文章
- poj1273 Drainage Ditches Dinic最大流
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 76000 Accepted: 2953 ...
- POJ1273:Drainage Ditches(最大流入门 EK,dinic算法)
http://poj.org/problem?id=1273 Description Every time it rains on Farmer John's fields, a pond forms ...
- POJ-1273 Drainage Ditches 最大流Dinic
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 65146 Accepted: 25112 De ...
- 2018.07.06 POJ1273 Drainage Ditches(最大流)
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Description Every time it rains on Farmer J ...
- poj-1273 Drainage Ditches(最大流基础题)
题目链接: Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 67475 Accepted ...
- 【网络流】POJ1273 Drainage Ditches
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 78671 Accepted: 3068 ...
- poj1273 Drainage Ditches
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 68414 Accepted: 2648 ...
- POJ1273 Drainage Ditches (网络流)
Drainage Ditches Time Limit: 1000MS Memor ...
- (网络流 模板 Edmonds-Karp)Drainage Ditches --POJ --1273
链接: http://poj.org/problem?id=1273 Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total ...
- poj1273 Drainage Ditches (最大流模板)
http://poj.org/problem?id=1273 Dinic算法 这是一道最大流的经典题 最大流尽量应该用边表,优于邻接矩阵(所以我写了邻接矩阵版的之后又写了个边表) 用了新学的Dinic ...
随机推荐
- Windows Server 2008 R2 SP1安装SQL 2012安装报错之0x858C001B
使用Windows Server 2008 R2 SP1安装SQL 2012的时候总是报这样一个错: SQL Server Setup has encountered the following er ...
- 分布式实时日志分析解决方案ELK部署架构
一.概述 ELK 已经成为目前最流行的集中式日志解决方案,它主要是由Beats.Logstash.Elasticsearch.Kibana等组件组成,来共同完成实时日志的收集,存储,展示等一站式的解决 ...
- 【Python学习笔记】有关包的基本知识
python的包(package)是一个有层次的文件目录结构.它定义了一个由模块和子包组成的Python应用程序执行环境. AAA/ __init__.py bbb.py CCC/ __init__. ...
- 2012年Elsevier旗下Computer Science期刊最新SCI影响因子排名
Latest Impact Factor figures from Elsevier's Computer Science Journals Medical Image Analysis Impact ...
- python基础===python实现截图
python实现全屏截图: from PIL import ImageGrab im = ImageGrab.grab() im.save('F:\\12.png')
- free函数在操作系统内存中的实现【转】
转自:http://www.2cto.com/kf/201210/160985.html 我一次性malloc十个单位节点的内存空间出来赋值给L, 现在我想一次性删除从第3个到第6个节点,我是这么做的 ...
- python之operator操作符函数
operator函数主要分为以下几类:对象比较.逻辑比较.算术运算和序列操作. 举例: #python 3.4 >>> operator.eq(1,2)False >>& ...
- 【bzoj4033】HAOI2015树上染色
树形dp. #include<bits/stdc++.h> #define N 2010 using namespace std; typedef long long ll; ,head[ ...
- dockerfile实例--安装nginx
[root@localhost ~]# vi Dockerfile //ADD FROM centos_with_net MAINTAINER frankie onez0714@.com RUN yu ...
- App推广
一行业常见名词解释 开发商:也叫CP,即Content Provider内容提供商的英文首字母缩写. 发行商(运营商):即代理CP开发出来的产品. 渠道:拥有用户,能够进行流量分发的公司,即可成为渠道 ...