(网络流 模板 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 ...
随机推荐
- Tomcat数据库连接池配置
Tomcat数据库连接池配置 1. Server.xml的配置 (1)找到tomcat所在目录下的conf\server.xml文件 (2)在文件最后一个</host> ...
- Dotfuscator Professional Edition获取代码发布和混淆代码
1 Dotfuscator Professional Edition 4.9 破解版 下载地址:http://www.pc0359.cn/downinfo/39815.html 备份地址:C:\D\9 ...
- Unity 5.1+ Assertion Library (断言库)
Unity 5.1+ ,加入了“断言库”,在 Asset 类中可以方便的找到需要使用断言的函数. UnityEngine.Assertions.Assert.IsNotNull( ) 为何使用断言 使 ...
- 安装使用phpStudy在本机配置php运行环境
前言: php开发的初学者,强烈推荐使用phpStudy集成环境,一方面这个的确很好用(本人电脑安装了jspStudy,可以同时调试php和jsp),另一方面呢,虽然本人是技术控,但对这些繁杂的安装部 ...
- springmvc中Controller方法的返回值
1.1 返回ModelAndView controller方法中定义ModelAndView对象并返回,对象中可添加model数据.指定view. 1.2 返回void 在controller方法形参 ...
- Windows 7 手动添加受信任证书教程
步骤如下: 1.点击开始-运行,如下图: 2.弹出"控制台"窗口如下,如下图: 3.点击"文件-添加/删除管理单元",如下图: 4.选择"证书&quo ...
- Codeforces 660A. Co-prime Array 最大公约数
A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- jquery节点获取
jQuery.parent(expr) 找父亲节点,可以传入expr进行过滤,比如$("span").parent()或者$("span").parent(& ...
- [转]docker 基本原理及快速入门
版权声明:原创作品, 来自海牛部落-青牛,http://hainiubl.com/topics/13 什么是docker Docker 是一个开源项目,诞生于 2013 年初,最初是 dotCloud ...
- 数据分页c#
存储过程分页的全套代码aspx页面的代码using System;using System.Collections.Generic;using System.Linq;using System.Web ...