poj 1273 Drainage Ditches 网络流最大流基础
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 59176 | Accepted: 22723 | 
Description
Farmer John knows not only how many gallons of water each ditch can
transport per minute but also the exact layout of the ditches, which
feed out of the pond and into each other and stream in a potentially
complex network.
Given all this information, determine the maximum rate at which
water can be transported out of the pond and into the stream. For any
given ditch, water flows in only one direction, but there might be a way
that water can flow in a circle.
Input
For each case, the first line contains two space-separated integers, N
(0 <= N <= 200) and M (2 <= M <= 200). N is the number of
ditches that Farmer John has dug. M is the number of intersections
points for those ditches. Intersection 1 is the pond. Intersection point
M is the stream. Each of the following N lines contains three integers,
Si, Ei, and Ci. Si and Ei (1 <= Si, Ei <= M) designate the
intersections between which this ditch flows. Water will flow through
this ditch from Si to Ei. Ci (0 <= Ci <= 10,000,000) is the
maximum rate at which water will flow through the ditch.
Output
Sample Input
5 4
1 2 40
1 4 20
2 4 20
2 3 30
3 4 10
Sample Output
50 //手打dinic,从我做起!
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 10000
#define eps 1e-9
const int inf=0x7fffffff; //无限大
//************************************************************************************** struct edge
{
int to,cap,rev;
};
vector<edge> g[maxn];
int level[maxn];
int iter[maxn];
void add_edge(int from,int to,int cap)
{
g[from].push_back((edge){to,cap,g[to].size()});
g[to].push_back((edge){from,0,g[from].size()-1});
}
void bfs(int s)
{
memset(level,-1,sizeof(level));
queue<int> que;
level[s]=0;
que.push(s);
while(!que.empty())
{
int v=que.front();
que.pop();
for(int i=0;i<g[v].size();i++)
{
edge &e=g[v][i];
if(e.cap>0&&level[e.to]<0)
{
level[e.to]=level[v]+1;
que.push(e.to);
}
}
}
}
int dfs(int v,int t,int f)
{
if(v==t)return f;
for(int &i=iter[v];i<g[v].size();i++)
{
edge &e=g[v][i];
if(e.cap>0&&level[v]<level[e.to])
{
int d=dfs(e.to,t,min(f,e.cap));
if(d>0)
{
e.cap-=d;
g[e.to][e.rev].cap+=d;
return d;
}
}
}
return 0;
}
int max_flow(int s,int t)
{
int flow=0;
while(1)
{
bfs(s);
if(level[t]<0)return flow;
memset(iter,0,sizeof(iter));
int f;
while((f=dfs(s,t,inf))>0)
flow+=f;
}
} int main()
{
int n,m;
while(cin>>n>>m)
{
for(int i=0;i<=m;i++)
g[i].clear();
int a,b,c;
for(int i=0;i<n;i++)
{
cin>>a>>b>>c;
add_edge(a,b,c);
}
cout<<max_flow(1,m)<<endl;
}
}
poj 1273 Drainage Ditches 网络流最大流基础的更多相关文章
- poj 1273 Drainage Ditches (网络流 最大流)
		
网络流模板题. ============================================================================================ ...
 - poj 1273 Drainage Ditches(最大流)
		
http://poj.org/problem?id=1273 Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Subm ...
 - POJ 1273 Drainage Ditches (网络最大流)
		
http://poj.org/problem? id=1273 Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Sub ...
 - poj 1273 Drainage Ditches【最大流入门】
		
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 63924 Accepted: 2467 ...
 - poj 1273 Drainage Ditches(最大流,E-K算法)
		
一.Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clove ...
 - POJ 1273 Drainage Ditches (网络流Dinic模板)
		
Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover ...
 - POJ 1273 Drainage Ditches 网络流 FF
		
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 74480 Accepted: 2895 ...
 - POJ 1273 Drainage Ditches【最大流】
		
题意:给出起点是一个池塘,M条沟渠,给出这M条沟渠的最大流量,再给出终点是一条河流,问从起点通过沟渠最多能够排多少水到河流里面去 看的紫书的最大流,还不是很理解,照着敲了一遍 #include< ...
 - POJ 1273 Drainage Ditches【最大流模版】
		
题意:现在有m个池塘(从1到m开始编号,1为源点,m为汇点),及n条有向水渠,给出这n条水渠所连接的点和所能流过的最大流量,求从源点到汇点能流过的最大流量 Dinic #include<iost ...
 
随机推荐
- 使用Netcat进行攻击
			
https://www.freebuf.com/column/135007.html 在网上找到了一个开启了ftp服务的服务: http://static.vhdong.com/Upload/Temp ...
 - eclipse安装阿里代码扫描插件
			
1.首先打开eclipse软件,点击工具栏上的Help,选择Install New Soft进行安装新的插件. 2.进入插件安装界面,点击Add,弹出插件地址填写界面,也可以直接在市场上搜索关键字al ...
 - Python_oldboy_自动化运维之路(八)
			
本节内容: 列表生成式,迭代器,生成器 Json & pickle 数据序列化 软件目录结构规范 作业:ATM项目开发 1.列表生成式,迭代器,生成器 1.列表生成式 #[列表生成] #1.列 ...
 - 洛谷P1782 旅行商的背包
			
传送门啦 这个题不用二进制优化的话根本不行,现学的二进制优化,调了一段时间终于A了,不容易.. 如果不懂二进制优化的话可以去看我那个博客 二进制优化多重背包入口 不想TLE,不要打memset,一定要 ...
 - GLOBAL_NAMES参数研究
			
最近在配置Stream时,发现必须要把GLOBAL_NAMES参数的指设置为TRUE,具体原因为何不知.但是发现在设置了该参数之后,数据库每天的物化视图刷新出现了问题.之后查明原因,是DBLINK出现 ...
 - (二)Jsoup 查找 DOM 元素
			
第一节: Jsoup 查找 DOM 元素 getElementById(String id) 根据 id 来查询 DOM getElementsByTag(String tagName) 根据 tag ...
 - SQL Server数据库存在判断语句及系统表简介
			
Transact-SQL Exists Sentences--判断数据库是否存在IF EXISTS(SELECT * FROM master.sysdatabases WHERE name=N'库名' ...
 - 日志、字段备注查询、自增ID联系设置、常用存储过程
			
-----获取数据字典SQL(表字段说明)SELECT [Table Name] = OBJECT_NAME(c.object_id), [Column Name] = c.name, ...
 - 20165203《Java程序设计》第三周学习总结
			
教材学习内容总结 1.类: (1)类的声明:class+类名 (2)类体:成员变量的声明+方法(局部变量+语句) 注意: 方法体内声明的局部变量只在方法内有效和书写位置有关. 局部变量和成员变量同名: ...
 - Knockout.Js官网学习Demo(使用VS2012或者VS2013均可打开)
			
https://pan.baidu.com/s/1gf9JZ8n#list/path=%2F