(网络流 模板 Edmonds-Karp)Drainage Ditches --POJ --1273
链接:
http://poj.org/problem?id=1273
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 63763 | Accepted: 24613 |
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
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
#define N 210
#define INF 0x3f3f3f3f int n, m, G[N][N], pre[N]; bool BFS(int Start, int End)
{
int p; queue<int>Q;
Q.push(Start); memset(pre, , sizeof(pre)); while(Q.size())
{
p = Q.front(), Q.pop(); if(p==End) return true; for(int i=; i<=End; i++)
{
if(!pre[i] && G[p][i])
{
pre[i] = p;
Q.push(i);
}
}
}
return false;
} int EM(int Start, int End)
{
int Max=;
while(BFS(Start, End)==true)
{
int Min=INF; for(int i=End; i!=Start; i=pre[i])
Min = min(Min, G[pre[i]][i]);
for(int i=End; i!=Start; i=pre[i])
{
G[pre[i]][i] -= Min;
G[i][pre[i]] += Min;
} Max += Min;
}
return Max;
} int main()
{
while(scanf("%d%d", &n, &m)!=EOF)
{
int i, u, v, p; memset(G, , sizeof(G));
for(i=; i<n; i++)
{
scanf("%d%d%d", &u, &v, &p);
G[u][v] += p;
} printf("%d\n", EM(, m));
}
return ;
}
(网络流 模板 Edmonds-Karp)Drainage Ditches --POJ --1273的更多相关文章
- (网络流 模板 Dinic) Drainage Ditches --POJ --1273
链接: http://poj.org/problem?id=1273 代码: //Dinic #include<stdio.h> #include<string.h> #inc ...
- Drainage Ditches - poj 1273(网络流模板)
题意:1是源点,m是汇点,求出来最大流量,没什么好说的就是练习最大流的模板题 ************************************************************* ...
- 网络流最经典的入门题 各种网络流算法都能AC。 poj 1273 Drainage Ditches
Drainage Ditches 题目抽象:给你m条边u,v,c. n个定点,源点1,汇点n.求最大流. 最好的入门题,各种算法都可以拿来练习 (1): 一般增广路算法 ford() #in ...
- 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 ...
- POJ 1273 Drainage Ditches(网络流dinic算法模板)
POJ 1273给出M条边,N个点,求源点1到汇点N的最大流量. 本文主要就是附上dinic的模板,供以后参考. #include <iostream> #include <stdi ...
- 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 (网络流 最大流)
网络流模板题. ============================================================================================ ...
- POJ 1273 Drainage Ditches(网络流,最大流)
Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover ...
随机推荐
- oracle rac 常见安装、管理错误
1. 安装CRS失败,或执行root.sh报错,可能原因: (1) 节点间的时间不同步,解决方法:使用ntp服务 (2) Linux下启用了默认的防火墙,导致执行root.sh报错: Failure ...
- Windows自带的端口转发工具netsh使用方法_DOS/BAT
Windows自带的端口转发工具netsh使用方法_DOS/BAT 作者:用户 来源:互联网 时间:2017-02-22 17:24:30 netsh 端口转发 摘要: 下面的代码在windows ...
- EasyUI多选的获取
function deletePRE() { var rows = $('#dg').datagrid('getSelections'); var ids = []; var other_ids = ...
- GridView上同时定义了 DataSource 和 DataSourceId
VS平台下ASP.NET网站的建立,我们常常要跟数据库打交道,获取数据库的信息,通过GridView控件进行显示,需要为GridView指定 DataSourceId或者DataSource,切忌不可 ...
- xcode10设置自定义代码快 - Xcode10新功能新内容
1. 2. 详情: Xcode10新功能新内容https://blog.csdn.net/u010960265/article/details/80630118
- Docker常见问题
问题 当我使用docke search mysql时,显示如下错误: [root@iZ25u61v97hZ opt]# docker search redis Segmentation Fault o ...
- c语言定义函数指针和typedef简写
二种方法来定义函数指针 #include<stdio.h> #include<stdlib.h> #include<Windows.h> int add(int a ...
- 解决安装Apache中出现checking for APR... no configure: error: APR not found. Please read the documentation的问题
Linux中安装Apache 编译出现问题: 解决办法: 1.下载所需要的软件包 wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz wg ...
- VINS-mono详细解读
VINS-mono详细解读 极品巧克力 前言 Vins-mono是香港科技大学开源的一个VIO算法,https://github.com/HKUST-Aerial-Robotics/VINS-Mono ...
- 使用bcp工具对boost库裁剪
有些时候,我们需要通过源代码来发布我们的产品,在使用了CI工具之后,一般我们要求每天对源码进行构建,以防止代码不可用了还不自知.如果我们使用了Boost库,我们就需要在构建的过程中将Boost同时构建 ...