POJ 1273 Drainage Ditches题解——S.B.S.
Drainage Ditches
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 67823 | Accepted: 26209 |
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
Output
Sample Input
5 4
1 2 40
1 4 20
2 4 20
2 3 30
3 4 10
Sample Output
50
Source
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cassert>
#include<climits>
#define maxn 210
using namespace std;
void find();
void flow();
void update();
struct Edge
{
int c;
int f;
}edge[maxn][maxn];
int n,m;
int s,t;
int residual[maxn][maxn];
int que[maxn*maxn],head,tail;
int pre[maxn];
bool vis[maxn];
int max_flow,min_flow;
void find()
{
int i,cu;
memset(vis,false,sizeof(vis));
memset(residual,,sizeof(residual));
memset(pre,,sizeof(pre));
head=;que[head]=s;pre[s]=s;vis[s]=true;tail=;
while(head<tail&&pre[t]==)
{
cu=que[head];
for(i=;i<=n;i++)
{
if(vis[i]==false)
{
if(edge[cu][i].c-edge[cu][i].f>)
{
residual[cu][i]=edge[cu][i].c-edge[cu][i].f;
pre[i]=cu;que[tail++]=i;vis[i]=true;
}
else if(edge[i][cu].f>)
{
residual[cu][i]=edge[i][cu].f;
pre[i]=cu;que[tail++]=i;vis[i]=true;
}
}
}
head++;
}
}
void flow()
{
int i=t,j;
if(pre[i]==)
{
min_flow=;return;
}
j=0x7fffffff;
while(i!=s)
{
if(residual[pre[i]][i]<j) j=residual[pre[i]][i];
i=pre[i];
}
min_flow=j;
}
void update()
{
int i=t;
if(pre[i]==) return;
while(i!=s)
{
if(edge[pre[i]][i].c-edge[pre[i]][i].f>)
edge[pre[i]][i].f+=min_flow;
else if(edge[i][pre[i]].f>)
edge[pre[i]][i].f+=min_flow;
i=pre[i];
}
}
void solve()
{
s=;t=n;
max_flow=;
while(true)
{
find();flow();
max_flow+=min_flow;
if(min_flow>) update();
else return;
}
}
int main()
{
std::ios::sync_with_stdio(false);
int i,u,v,c;
while(scanf("%d %d",&m,&n)!=EOF)
{
memset(edge,,sizeof(edge));
for(i=;i<m;i++)
{
scanf("%d %d %d",&u,&v,&c);
edge[u][v].c+=c;
}
solve();
printf("%d\n",max_flow);
}
return ;
}
POJ 1273 Drainage Ditches题解——S.B.S.的更多相关文章
- 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 - [最大流模板题] - [EK算法模板][Dinic算法模板 - 邻接表型]
题目链接:http://poj.org/problem?id=1273 Time Limit: 1000MS Memory Limit: 10000K Description Every time i ...
- poj 1273 Drainage Ditches 最大流入门题
题目链接:http://poj.org/problem?id=1273 Every time it rains on Farmer John's fields, a pond forms over B ...
- 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
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 67387 Accepted: 2603 ...
- POJ 1273 Drainage Ditches -dinic
dinic版本 感觉dinic算法好帅,比Edmonds-Karp算法不知高到哪里去了 Description Every time it rains on Farmer John's fields, ...
- Poj 1273 Drainage Ditches(最大流 Edmonds-Karp )
题目链接:poj1273 Drainage Ditches 呜呜,今天自学网络流,看了EK算法,学的晕晕的,留个简单模板题来作纪念... #include<cstdio> #include ...
- POJ 1273 Drainage Ditches(网络流dinic算法模板)
POJ 1273给出M条边,N个点,求源点1到汇点N的最大流量. 本文主要就是附上dinic的模板,供以后参考. #include <iostream> #include <stdi ...
随机推荐
- Android使用ViewPager实现左右循环滑动及轮播效果
边界的时候会看到一个不能翻页的动画,可能影响用户体验.此外,某些区域性的ViewPager(例如展示广告或者公告之类的ViewPager),可能需要自动轮播的效果,即用户在不用滑动的情况下就能够看到其 ...
- Java日期时间操作的一些方法
1. 获得Calendar实例: Calendar c = Calendar.getInstance(); 2. 定义日期/时间的格式: SimpleDateFormat sdf =new Simpl ...
- java Byte[] to String(hex)
1. 字节数组转换成16进制字符展示 2.代码 package com.goodfan; public class ByteArrayToString { private static char[] ...
- 学习笔记:HTML5 Canvas绘制简单图形
HTML5 Canvas绘制简单图形 1.添加Canvas标签,添加id供js操作. <canvas id="mycanvas" height="700" ...
- 6、ASP.NET MVC入门到精通——ASP.Net的两种开发方式
本系列目录:ASP.NET MVC4入门到精通系列目录汇总 目前,ASP.NET中两种主流的开发方式是:ASP.NET Webform和ASP.NET MVC.从下图可以看到ASP.NET WebFo ...
- 关于webStrom-11.1配置less且自动生成.css和自动压缩为.min.css/.min.js
网上看过很多配置思路,自己总结了以下, 就把我个人配置的顺序以及材料分享下,webstrom以下简称WB 1.配置less需要安装nodejs,自行安装.因为要用到npm.我是直接把npm解压到C盘根 ...
- Android Fragment使用(二) 嵌套Fragments (Nested Fragments) 的使用及常见错误
嵌套Fragment的使用及常见错误 嵌套Fragments (Nested Fragments), 是在Fragment内部又添加Fragment. 使用时, 主要要依靠宿主Fragment的 ge ...
- [转]利用JitPack发布自己项目让别人可以在dependencies中compile的简单方法
JitPack的地址为:https://jitpack.io/ 发布 登陆 jitpack 在编辑框中输入github的网址,完成后点击LookUp 使用 点击 Get it. 之后网页就会自动导航到 ...
- Java中的常见面试题
1.sleep()和wait()的区别: 两者都可以控制线性进程,阻塞进程.区别是: -----|sleep():释放CPU,不释放资源(锁).可以通过指定时间来使它自动醒来,时间不到只能调用iter ...
- iOS---searchBar 搜索框 光标初始位置后移
#import <UIKit/UIKit.h> @interface SearchBar : UITextField @property (nonatomic,strong) UIButt ...