Drainage Ditches
点击打开链接
意甲冠军:有因雨池塘,通过修通渠道流失。如何污水排放达?
解决:古典最大流量,通过改变容量,为了减少使用流量,了空间优化
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<queue>using namespace std;const int maxn = 1005;
#define INF 0xfffffff
int n, m, u, v, value, sum, start, end;
int pre[ maxn ], cap[ maxn ][ maxn ], flow[ maxn ][ maxn ], dis[ maxn ];int EK (){queue< int > Q;sum = 0;while( 1 ){Q.push( start );memset( dis, 0, sizeof( dis ) );dis[ start ] = INF;while( !Q.empty() ){int temp = Q.front();Q.pop();for( int i = 1; i <= m; ++i ){if( ! dis[ i ] && cap[ temp ][ i ] > 0 ){dis[ i ] = min( dis[ temp ], cap[ temp ][ i ] ); pre[ i ] = temp;Q.push( i );}}}if( dis[ m ] == 0 )break;sum += dis[ m ];for( int i = end; i != start; i = pre[ i ] ){cap[ pre[ i ] ][ i ] -= dis[ m ];cap[ i ][ pre[ i ] ] += dis[ m ];}}printf( "%d\n", sum );
}int main(){while( scanf( "%d%d", &n, &m ) != EOF ){memset( cap, 0, sizeof( cap ) );memset( flow, 0, sizeof( flow ) );start = 1, end = m;for( int i = 0; i < n; ++i ){scanf( "%d%d%d", &u, &v, &value );cap[ u ][ v ] += value;}EK( );}
}/*
5 4
1 2 40
1 4 20
2 4 20
2 3 30
3 4 1050
*/
Drainage Ditches相关推荐
- 网络流--最大流--POJ 1273 Drainage Ditches
链接 Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clov ...
- Drainage Ditches POJ1273
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 93263 Accepted: 36174 试题链接 文章目录 Descripti ...
- USACO Section 4.2 Drainage Ditches(最大流)
最大流问题.ISAP算法.注意可能会有重边,不过我用的数据结构支持重边.距离d我直接初始化为0,也可以用BFS逆向找一次. -------------------------------------- ...
- [POJ 1273]Drainage Ditches
[问题描述] Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch ...
- poj1273 Drainage Ditches
蒟蒻的blog POJ 1273 Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Memory Limit: 10000K Total ...
- 网络流 - Drainage Ditches - HDU - 1532
Problem Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite ...
- usaco Drainage Ditches(网络流dinic模板)
模板题 /* ID:jinbo wu TASK:ditch LANG:C++ */#include<bits/stdc++.h> using namespace std; #define ...
- POJ 1273 Drainage Ditches
网络流. 题意非常easy.给出单向边,容量. 找最大流.注意重边要加起来.g[u][v].c+=c; 第一次写网络流. 也是第一个网络流的题. 看了两天,理解了之后就唰唰唰的写出来了. 大概可能是E ...
- 【网络流】解题报告:luogu P2740 [USACO4.2]草地排水Drainage Ditches(Edmonds-Karp增广路,最大流模板)
题目链接:草地排水 若一条从源点到汇点的路径上各条边的剩余容量都大于0,则称这条路径为一条增广路. Edmonds-Karp增广路的策略就是不断用bfs寻找增广路,直至网络中不在存在增广路为止. 在每 ...
最新文章
- neo4j 知识图谱_知识图谱里的知识存储:neo4j的介绍和使用
- java注解编程_java 注解 基本原理 编程实现
- iTunes只能装C盘吗_C盘清理简单汇总
- GYM 101669F - Binary Transformations
- 整合php和mysql lnmp,安装配置LNMP服务器(Nginx+PHP+MySQL)
- JZOJ 1286. 太空电梯
- 连接共享打印机出现0x000000bcb问题的解决方法
- MapGIS格式转ArcGIS方法
- 学计算机干眼,电脑族预防干眼的7个小妙招_39健康网
- Android 7.0应用冷启动流程分析
- 马士兵oracle_,马士兵oracle视频教程学习笔记个人整理
- 【随手写】JS过滤所有script正则
- CocosCreator Effect (Shader) - 反九宫格就(Sliced)补偿
- 一起来学Kotlin:概念:7. Kotlin 函数介绍:扩展函数,中缀函数,运算符函数,带有varrag输入的函数
- latex 跳转标签_LaTeX 之 \label 的运用
- 关于iPad上百度网盘中压缩包下载不能找到的问题
- 海豚php如何添加节点,python+matplotlib绘制简单的海豚(顶点和节点的操作)
- SpringBoot集成支付宝沙箱手机网站支付详细流程和踩坑分享
- mysql 重量 什么类型_航空货物运输中的计费重量,指货物毛重与体积重量中的高者。...
- PanGu STM32MP1开发环境搭建