POJ1273(最大流入门)
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 70333 | Accepted: 27336 |
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 Dinic实现最大流.
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
const int MAXN=;
const int INF=0x3f3f3f3f;
int arc[MAXN][MAXN];
int n,m;
int level[MAXN];
bool bfs(int src,int ter)
{
memset(level,-,sizeof(level));
queue<int> que;
que.push(src);
level[src]=;
while(!que.empty())
{
int u=que.front();que.pop();
for(int i=;i<=n;i++)
{
if(level[i]<&&arc[u][i]>)
{
que.push(i);
level[i]=level[u]+;
}
}
}
if(level[ter]>) return true;
else return false;
} int dfs(int u,int ter,int f)
{
if(u==ter) return f;
for(int i=;i<=n;i++)
{
int d;
if(arc[u][i]>&&level[i]==level[u]+&&(d=dfs(i,ter,min(arc[u][i],f))))
{
arc[u][i]-=d;
arc[i][u]+=d;
return d;
}
}
return ;
}
int max_flow(int src,int ter)
{
int ans=;
int d;
while(bfs(src,ter))
{
while(d=dfs(src,ter,INF)) ans+=d;
}
return ans;
}
int main()
{
// freopen("input.in","r",stdin);
while(scanf("%d%d",&m,&n)!=EOF)
{
memset(arc,,sizeof(arc));
for(int i=;i<m;i++)
{
int from,to,w;
scanf("%d%d%d",&from,&to,&w);
arc[from][to]+=w;
}
int res=max_flow(,n);
printf("%d\n",res);
}
return ;
}
POJ1273(最大流入门)的更多相关文章
- 使用Guava RateLimiter限流入门到深入
前言 在开发高并发系统时有三把利器用来保护系统:缓存.降级和限流 缓存: 缓存的目的是提升系统访问速度和增大系统处理容量 降级: 降级是当服务出现问题或者影响到核心流程时,需要暂时屏蔽掉,待高峰或者问 ...
- JavaIo流入门篇之字节流基本使用。
一 基本知识了解( 字节流, 字符流, byte,bit是啥?) /* java中字节流和字符流之前有接触过,但是一直没有深入的学习和了解. 今天带着几个问题,简单的使用字节流的基本操作. 1 什么 ...
- Java-io流入门到精通详细总结
IO流:★★★★★,用于处理设备上数据. 流:可以理解数据的流动,就是一个数据流.IO流最终要以对象来体现,对象都存在IO包中. 流也进行分类: 1:输入流(读)和输出流(写). 2:因为处理的数据不 ...
- IO流入门-第十三章-File相关
/* java.io.File 1.File和流无关,不能通过该类完成文件的读写 2.File是文件和目录路径名的抽象变现形式. */ import java.io.*; public class F ...
- IO流入门-第十二章-ObjectInputStream_ObjectOutputStream
DataInputStream和DataOutputStream基本用法和方法示例,序列化和反序列化 import java.io.Serializable; //该接口是一个“可序列化”的 ,没有任 ...
- IO流入门-第十一章-PrintStream_PrintWriter
DataInputStream和DataOutputStream基本用法和方法示例 /* java.io.PrintStream:标准的输出流,默认打印到控制台,以字节方式 java.io.Print ...
- IO流入门-第十章-DataInputStream_DataOutputStream
DataInputStream和DataOutputStream基本用法和方法示例 /* java.io.DataOutputStream 数据字节输出流,带着类型写入 可以将内存中的“int i = ...
- IO流入门-第九章-BufferedReader_BufferedWriter复制
利用BufferedReader和BufferedWriter进行复制粘贴 import java.io.*; public class BufferedReader_BufferedWriterCo ...
- IO流入门-第八章-BufferedWriter
BufferedWriter基本用法和方法示例 import java.io.*; public class BufferedWriterTest01 { public static void mai ...
- IO流入门-第七章-BufferedReader
BufferedReader基本用法和方法示例 /* 字节 BufferedInputStream BufferedOutputStream 字符 BufferedReader:带有缓冲区的字符输入流 ...
随机推荐
- Spring入门2. IoC中装配Bean
Spring入门2. IoC中装配Bean 20131125 前言: 上一节学习了Spring在JavaProject中的配置,通过配置文件利用BeanFactory和ApplicationConte ...
- 转载:【Oracle 集群】RAC知识图文详细教程(五)--特殊问题和实战经验
文章导航 集群概念介绍(一) ORACLE集群概念和原理(二) RAC 工作原理和相关组件(三) 缓存融合技术(四) RAC 特殊问题和实战经验(五) ORACLE 11 G版本2 RAC在LINUX ...
- 十三、dbms_flashback(用于激活或禁止会话的flashback特征)
1.概述 作用:用于激活或禁止会话的flashback特征,为了使得普通用户可以使用该包,必须要将执行该包的权限授予这些用户,grant execute on dbms_flashback to sc ...
- hystrix -hystrixCommand配置介绍
public @interface HystrixCommand { // HystrixCommand 命令所属的组的名称:默认注解方法类的名称 String groupKey() default ...
- 集成xadmin源码到项目的正式姿势
xadmin是强大的,但是为了更好的后期定制开发,可能会修改到xadmin的源码. 因此还是推荐将xadmin源码集成到自己的项目中. 1.pip install xadmin 安装xadmin的模块 ...
- 官方文档-Linux服务器集群系统(一)
转载-Linux服务器集群系统(一) LVS项目介绍 章文嵩 (wensong@linux-vs.org)2002 年 3 月 本文介绍了Linux服务器集群系统--LVS(Linux Virtual ...
- Javascript-- jQuery动画篇(2)
动画效果 前面的 hide/show,slide in/out 其实也具有动画效果,本篇介绍使用 animate()实现自定义动画效果. 基本语法如下: $(selector).animate({pa ...
- 第7课:sql注入、操作session、cookie实例、网络编程、操作Excel
1. 简单讲一些sql注入的内容 name = 'zdq' sex = '女' cur.execute("select * from bt_stu where real_name='%s'& ...
- linux下c语言源码编译
一.源码编译过程 源码 ---> 预处理 ---> 编译 ---> 汇编 ---> 链接 --->执行 我们可以把它分为三部分来完成: ./configure ...
- Slice header 中的frame_num的含义?
Frame_num表示解码的顺序.该图像是参考帧的时候,Frame_num才有意义.非参考帧的frame_num在poc type为2或3时,用于poc值的计算. H264中frame_num定义如下 ...