POJ1273 Drainage Ditches (网络流)
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 69983 | Accepted: 27151 |
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
【分析】我直接套的树上的网络流标号法模板。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#define inf 0x3f3f3f3f
#define mod 1000000007
typedef long long ll;
using namespace std;
const int N=;
const int M=;
int s,t,n,m,num,k;
int customer[N][N];
int flow[N][N];
int house[M],last[M];
int pre[N],minflow[N]; void BFS() {
queue<int>q;
int p=;
memset(flow,,sizeof(flow));
minflow[]=inf;
while() {
while(!q.empty())q.pop();
for(int i=; i<N; i++)pre[i]=-;
pre[]=-;
q.push();
while(!q.empty()&&pre[t]==-) {
int v=q.front();
q.pop();
for(int i=; i<t+; i++) {
if(pre[i]==-&&(p=customer[v][i]-flow[v][i])) {
pre[i]=v;
q.push(i);
minflow[i]=min(p,minflow[v]);
}
}
}
if(pre[t]==-)break;
int j;
for(int i=pre[t],j=t; i>=; j=i,i=pre[i]) {
flow[i][j]+=minflow[t];
flow[j][i]=-flow[i][j];
}
}
for(int i=; i<t; i++)p+=flow[i][t];
printf("%d\n",p);
}
int main() {
while(~scanf("%d%d",&m,&n)) {
memset(last,,sizeof(last));
memset(customer,,sizeof(customer));
s=;
t=n;
int a,b,c;
for(int i=; i<=m; i++){
scanf("%d%d%d",&a,&b,&c);
customer[a][b]+=c;
}
BFS();
}
return ;
}
POJ1273 Drainage Ditches (网络流)的更多相关文章
- poj1273 Drainage Ditches Dinic最大流
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 76000 Accepted: 2953 ...
- 【网络流】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 ...
- 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: 63339 Accepted: 2443 ...
- HDU1532 Drainage Ditches 网络流EK算法
Drainage Ditches Problem Description Every time it rains on Farmer John's fields, a pond forms over ...
- POJ-1273 Drainage Ditches 最大流Dinic
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 65146 Accepted: 25112 De ...
- USACO 4.2 Drainage Ditches(网络流模板题)
Drainage DitchesHal Burch Every time it rains on Farmer John's fields, a pond forms over Bessie's fa ...
- NYOJ 323 Drainage Ditches 网络流 FF 练手
Drainage Ditches 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 Every time it rains on Farmer John's fields, ...
随机推荐
- 【ZigZag Conversion】cpp
题目: The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows l ...
- QA面试题:之一(中英文题目、难度:简单)
QA面试题:之一(中英文题目.难度:简单)
- django-settings里mysql连接配置
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'dailyfresh', 'HOST': 'loca ...
- Python全栈工程师(多继承、函数重写)
ParisGabriel 每天坚持手写 一天一篇 决定坚持几年 为了梦想为了信仰 开局一张图 Python人工智能从入门到精通 补充: 对象 --------- ...
- [Ceres]C++优化库
官网教程: http://ceres-solver.org/nnls_tutorial.html 定义了一个最小二乘法求解器 自动求导的功能
- 洛谷P2678跳石头(提高)
题目背景 一年一度的“跳石头”比赛又要开始了! 题目描述 这项比赛将在一条笔直的河道中进行,河道中分布着一些巨大岩石.组委会已经选择好了两块岩石作为比赛起点和终点. 在起点和终点之间,有 N 块岩石( ...
- Qt(1)
Qt Qt开发图形界面软件,可以跨win.linux.mac平台.移动端,使用c++开发 Qt采用所见即所得的UI设计(UI设计和代码是联动的),GUI界面编辑信号和槽,由开发环境自动生成c++代码, ...
- 【bzoj5056】OI游戏 最短路+矩阵树定理
题目描述 给出一张无向图,求满足 0号点到所有点的路径长等于原图中它们之间最短路 的生成树的个数. 输入 第一行一个整数N,代表原图结点. 接下来N行,每行N个字符,描绘了一个邻接矩阵.邻接矩阵中, ...
- Android应用如何打包?
android app开发结束后,就需要对app进行打包.部署与发布了,那对于android初学者而言,如何对apk进行打包呢?今天小编就为大家分享一二,一起来看看吧~~ aapt package - ...
- [SQL Server]关于标识列,标识从1开始计数的的方法
DBCC CHECKIDENT ('表名', RESEED, 0) //从30开始 DBCC CHECKIDENT (jobs, RESEED, 30)