Drainage Ditches--hdu1532(网络流 模板)
http://acm.hdu.edu.cn/showproblem.php?pid=1532
Drainage Ditches
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13790 Accepted Submission(s): 6527
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.
题目大意就是求最大流
是模板题
本来之前学的时候用了两种方法 第二种是链表 之前根本不知道链表是什么 现在算是懂一点了吧
时间真是一个好东西
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stdlib.h>
#include <vector>
#include <queue> using namespace std;
#define memset(a,b) memset(a,b,sizeof(a))
#define N 250
#define INF 0xfffffff
int pre[N];
int n,m,G[N][N]; bool bfs(int s,int e)
{
queue<int>Q;
Q.push(s);
memset(pre,);
while(!Q.empty())
{
int p=Q.front();
Q.pop();
if(p==e)
return true;
for(int i=;i<=e;i++)
{
if(!pre[i] && G[p][i])
{
Q.push(i);
pre[i]=p;
}
}
}
return false;
} int KM(int s,int e)
{
int Max=;
while(bfs(s,e)==true)
{
int Min=INF;
for(int i=e;i!=s;i=pre[i])
{
Min=min(Min,G[pre[i]][i]);
}
for(int i=e;i!=s;i=pre[i])
{
G[i][pre[i]]+=Min;
G[pre[i]][i]-=Min;
}
Max+=Min;
}
return Max;
}
int main()
{
int u,v,w;
while(scanf("%d %d",&n,&m)!=EOF)
{
memset(G,);
for(int i=;i<n;i++)
{
scanf("%d %d %d",&u,&v,&w);
G[u][v]+=w;
}
printf("%d\n",KM(,m));
}
return ;
}
Drainage Ditches--hdu1532(网络流 模板)的更多相关文章
- POJ 1273 - Drainage Ditches - [最大流模板题] - [EK算法模板][Dinic算法模板 - 邻接表型]
题目链接:http://poj.org/problem?id=1273 Time Limit: 1000MS Memory Limit: 10000K Description Every time i ...
- POJ1273 Drainage Ditches (网络流)
Drainage Ditches Time Limit: 1000MS Memor ...
- HDU 1532 Drainage Ditches (网络流)
A - Drainage Ditches Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
- POJ 1273 Drainage Ditches(网络流,最大流)
Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover ...
- POJ_1273 Drainage Ditches 【网络流】
一.题面 Drainage Ditches 二.分析 网络流的裸题. 1 Edmonds-Karp算法 求解网络流其实就是一个不断找增广路,然后每次找到一条增广路后更新残余网络的一个过程. EK算法主 ...
- HDU 1532 Drainage Ditches (最大网络流)
Drainage Ditches Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) To ...
- POJ 1273 Drainage Ditches(网络流dinic算法模板)
POJ 1273给出M条边,N个点,求源点1到汇点N的最大流量. 本文主要就是附上dinic的模板,供以后参考. #include <iostream> #include <stdi ...
- nyoj_323:Drainage Ditches(网络流入门)
题目链接 网络流入门@_@,此处本人用的刘汝佳的Dinic模板 #include<bits/stdc++.h> using namespace std; const int INF = 0 ...
- hdoj 1532 Drainage Ditches(最大网络流)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1532 思路分析:问题为最大网络流问题,给定一个有向图,需要求解该有向图的最大网络流,使用Edmonds ...
- [Poj1273]Drainage Ditches(网络流)
Description 给图,求最大流 最大流模板题,这里用dinic Code #include <cstdio> #include <cstring> #include & ...
随机推荐
- 在Github上删除一个项目
最近在Github上浏览,不小心fork了一个项目.想删除,现在记录下来. 1.点击选择fork的项目,以gubai为例 2.进入后,点击Settings 3.进入页面后,点击Delete this ...
- Linux常用的操作指令
1.pwd-显示当前所在位置 2.cd-进入当前目录 3.cd..-返回上一级目录 4..ls命令参数选项有很多,ls也是经常使用到的命令.如果不清楚命令的使用方式可以直接 ls --help来查看 ...
- Asp.Net Core 入门(四)—— Model、View、Controller
和我们学习Asp.Net MVC一样,Asp.Net Core MVC的Model.View.Controller也和我们熟悉的Asp.Net MVC中的相似.不同的是我们在使用Asp.Net Cor ...
- merge dict key
#!/usr/local/python # -*- coding:utf-8 -*-user_dict = {'python': 23, 'Python': 51, '机器':10, 'PYTHON' ...
- 打开VS2015提示“重新启动处于挂起状态。请在启动Visual Studio”之前重新启动
昨晚安装了VS2015,今天打开VS2015提示[“重新启动处于挂起状态.请在启动Visual Studio”之前重新启动] 这里重新启动指的是重启电脑 解决方法: 电脑需要重启电脑
- springmvc @RequestParam @RequestBody @PathVariable 等参数绑定注解详解
简介: handler method 参数绑定常用的注解,我们根据他们处理的Request的不同内容部分分为四类:(主要讲解常用类型) A.处理requet uri 部分(这里指uri templat ...
- 前端打包--source-map=false作用
参考:http://www.cnblogs.com/axl234/p/6500534.htmlng serve默认会产生.map文件,该文件保存有原始代码与运行代码的映射关系, 浏览器可以通过它找到原 ...
- ç7—UIViewController
UIViewController继承了UIResponder,而UIResponder继承了NSObject,UIViewController是所有视图控制器的父类. 在MVC模式中,UIViewCo ...
- Day02:我的Python学习之路
1.初识模块 Python的强大之处在于他有非常丰富和强大的标准库和第三方库,现在简单的学习2个常见的标准库——sys和os. (1)系统的标准库sys # Author:GCL # 系统的标准库sy ...
- 6 SQL 函数、谓词、CASE表达式
6 函数.谓词.CASE表达式 6-1 各种各样的函数 /* 所谓函数,就是输入某一值得到相应输出结果的功能.输入值称为参数(parameter),输出值称为返回值. 函数大致可以分为以下几种 : 算 ...