POJ 1273 Drainage Ditches 网络流 FF
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 74480 | Accepted: 28953 |
Description
drainage ditches so that Bessie's clover patch is never covered in water. Instead, the water is drained to a nearby stream. Being an ace engineer, Farmer John has also installed regulators at the beginning of each ditch, so he can control at what rate water
flows into that ditch.
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
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
代码:
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int maxn=1005;
const int INF=0x3f3f3f3f;
int capacity[maxn][maxn],flow[maxn][maxn];
int v;
int networkflow(int source, int sink) {
int totalflow=0;
memset(flow,0,sizeof(flow));
while(true) {
vector<int> parent(maxn,-1);
queue<int> q;
parent[source]=source;
q.push(source);
while(!q.empty()) {
int here=q.front();q.pop();
for(int there=0;there<v;++there) {
if(capacity[here][there]-flow[here][there]>0&&parent[there]==-1) {
parent[there]=here;
q.push(there);
}
}
}
if(parent[sink]==-1) break;
int amount=INF;
for(int p=sink;p!=source;p=parent[p]) {
amount=min(amount,capacity[parent[p]][p]-flow[parent[p]][p]);
}
for(int p=sink;p!=source;p=parent[p]) {
flow[parent[p]][p]+=amount;
flow[p][parent[p]]-=amount;
}
totalflow+=amount;
}
return totalflow;
}
int main() {
int m,n;
while(~scanf("%d%d",&m,&n)) {
v=n;
memset(capacity,0,sizeof(capacity));
for(int i=0;i<m;++i) {
int x,y,c;
scanf("%d%d%d",&x,&y,&c);
capacity[x-1][y-1]+=c;
}
printf("%d\n",networkflow(0,n-1));
}
return 0;
}
POJ 1273 Drainage Ditches 网络流 FF的更多相关文章
- 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 网络流最大流基础
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 59176 Accepted: 2272 ...
- 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: 67387 Accepted: 2603 ...
- POJ 1273 Drainage Ditches(网络流dinic算法模板)
POJ 1273给出M条边,N个点,求源点1到汇点N的最大流量. 本文主要就是附上dinic的模板,供以后参考. #include <iostream> #include <stdi ...
- POJ 1273 Drainage Ditches(网络流,最大流)
Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover ...
- 网络流最经典的入门题 各种网络流算法都能AC。 poj 1273 Drainage Ditches
Drainage Ditches 题目抽象:给你m条边u,v,c. n个定点,源点1,汇点n.求最大流. 最好的入门题,各种算法都可以拿来练习 (1): 一般增广路算法 ford() #in ...
随机推荐
- N厂劳力士黑水鬼V7出了1年,如今依旧被追捧,供不应求
今天和大家一起来谈谈,风靡复刻界的潜航者,国人眼中的一劳永逸,何为一劳永逸,即(用这个腕表能省很多事)真的有这么牛?其实不然只要是机械腕表都会有或多或少的问题,一劳永逸更多的是指腕表的质量给力,所谓潜 ...
- [Bayesian] “我是bayesian我怕谁”系列 - Latent Variables
下一章有意讲讲EM和变分推断的内容. EM和变分推断的内容能Google到很多,虽然质量乘次不齐,但本文也无意再赘述那么些个细节. 此处记录一些核心思想,帮助菜鸡形成整体上的认识.不过,变分推断也不是 ...
- swift之函数式编程(四)
文章内容来自<Functional Programing in Swift>,具体内容请到书中查阅 Map, Filter, Reduce Functions that take func ...
- 操作系统--进程管理1--单个CPU情况
1.进程概念 进程:一个正在执行的程序:操作系统提出进程概念目的:是为了跟踪程序在执行期间的状态.而程序只是一段代码,是一个静态的概念 无法准确描述程序执行时候发生的一切.程序代码被加载进内存后就以进 ...
- Java反射机制能够获取的信息,与应用
一.什么是Java反射机制? [1]反射机制是在运行状态中,对于任何一个类,都能够知道这个类的所有属性和方法: [2]对于任意一个对象,都能够调用它的任意一个属性和方法: 像这种动态获取类的信息以及动 ...
- Winsock网络编程笔记(1)----入门
今天第一次接触winsock网络编程,看的资料是Windows网络编程第二版.通过博客记住自己的看书笔记.. 在这里贴出第一个程序,虽然程序什么都没做,但以此作为入门,熟悉其网络编程风格.. #inc ...
- MapReduce简单分析
在Map端 数据从Map中写入环形缓冲区,进行分区,分区时达到80%后溢出写入到磁盘,这几步同步进行 中间有个Shuffle过程 Reduce端 执行完Map 后到Reduce内存中,进行sort和m ...
- Android 开发笔记___SD卡基本操作
package com.example.alimjan.hello_world; /** * Created by alimjan on 7/5/2017. */ import android.ann ...
- AngularJS学习篇(二十三)
AngularJS 路由 AngularJS 路由允许我们通过不同的 URL 访问不同的内容. 通过 AngularJS 可以实现多视图的单页Web应用(single page web applica ...
- 透过浏览器看HTTP缓存[转载]
http://www.admin10000.com/document/6299.html 作为前端开发人员,对于我们的站点或应用的缓存机制我们能做的似乎不多,但这些却是与我们关注的性能息息相关 ...