POJ 1273 Drainage Ditches 最大流
很裸的最大流问题,不过注意会有重边,o(╯□╰)o,被阴了WA了一发 还有就是要用long long
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <string>
#include <iostream>
#include <map>
#include <cstdlib>
#include <list>
#include <set>
#include <queue>
#include <stack>using namespace std;typedef long long LL;
const int maxn = 205;
const int maxm = 205;
const int INF = INT_MAX / 2;
LL flow[maxn][maxn],C[maxn][maxn];
int n,m;void input() {memset(C,0,sizeof(C));for(int i = 1;i <= m;i++) {int a,b,c; scanf("%d%d%d",&a,&b,&c);C[a][b] += c;}
}LL alpha[maxn];
int pre[maxn];
int q[maxn + 20],qs,qe;void solve() {int s = 1,t = n;memset(flow,0,sizeof(flow));while(1) {for(int i = s + 1;i <= t;i++) pre[i] = -2;pre[s] = -1;qs = 0; qe = 1; q[qs] = s;alpha[s] = 1e13;while(qs < qe && pre[t] == -2) {int v = q[qs]; qs++;for(int i = s;i <= t;i++) {if(pre[i] == -2 && C[v][i] - flow[v][i] != 0) {alpha[i] = min(alpha[v],C[v][i] - flow[v][i]);pre[i] = v;q[qe++] = i;}}}if(pre[t] == -2) break;for(int i = t;pre[i] != -1;i = pre[i]) {flow[pre[i]][i] += alpha[t];flow[i][pre[i]] = -flow[pre[i]][i];}}LL ans = 0;for(int i = s;i < t;i++) ans += flow[i][t];printf("%lld\n",ans);
}int main() {while(scanf("%d%d",&m,&n) != EOF) {input();solve();}return 0;
}
转载于:https://www.cnblogs.com/rolight/p/3869683.html
POJ 1273 Drainage Ditches 最大流相关推荐
- POJ - 1273 Drainage Ditches(最大流)
题目链接:点击查看 题目大意:现在一共有n个节点,需要修建m条水渠将池塘的水引入小溪,点1代表池塘,点n代表小溪,每条水渠都有一定的排水能力,问最大的排水效率是多少 题目分析:网络流的模板题,直接套板 ...
- 网络流--最大流--POJ 1273 Drainage Ditches
链接 Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clov ...
- [POJ 1273]Drainage Ditches
[问题描述] Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch ...
- POJ 1273 Drainage Ditches
网络流. 题意非常easy.给出单向边,容量. 找最大流.注意重边要加起来.g[u][v].c+=c; 第一次写网络流. 也是第一个网络流的题. 看了两天,理解了之后就唰唰唰的写出来了. 大概可能是E ...
- [USACO4.2] 草地排水 Drainage Ditches (最大流)
题目背景 在农夫约翰的农场上,每逢下雨,贝茜最喜欢的三叶草地就积聚了一潭水.这意味着草地被水淹没了,并且小草要继续生长还要花相当长一段时间.因此,农夫约翰修建了一套排水系统来使贝茜的草地免除被大水淹没 ...
- POJ 1273 Dinic
题意 传送门 POJ 1273 Drainage Ditches 题解 最大流模板题,使用 DinicDinicDinic 算法求解. #include <algorithm> #incl ...
- poj1273 Drainage Ditches
蒟蒻的blog POJ 1273 Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Memory Limit: 10000K Total ...
- USACO Section 4.2 Drainage Ditches(最大流)
最大流问题.ISAP算法.注意可能会有重边,不过我用的数据结构支持重边.距离d我直接初始化为0,也可以用BFS逆向找一次. -------------------------------------- ...
- Drainage Ditches POJ1273
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 93263 Accepted: 36174 试题链接 文章目录 Descripti ...
最新文章
- 菲律宾政府网站被黑!
- OC第二节 继承、初始化⽅法、便利构造器
- ArcGIS Server SOE开发之奇怪异常:
- WdatePicker日期控件使用与值获取,以及选择日期完毕触发事件
- 好久不上来,发现这个世界变得真是快啊,都.NET 2.0 AJAX了~~
- python源码中的学习笔记_第10章_面向对象的特征、特殊方法与属性、以及深浅拷贝
- 【源代码】Image Deformation Using Moving Least Squares算法的实现
- python画哆啦a梦图片_画了个多啦A梦,但是感觉怪怪的
- Django在Window下的部署
- Internet Tv Radio Player v5.2
- java基础类库——数字操作类(五)
- 【图解CAN总线】-2-详述CAN总线电平
- 提交百度快速收录真的能达到秒收录吗
- 关于Chartboost的视频广告
- 前端页面如何获取高德地图
- 引用作为函数的返回值
- 括号画家(括号匹配)
- snmpwalk的报文检测
- Linux后端开发-POSIX标准以及shell编程
- 【4】RagTag-基于近缘/同物种的基因组同源组装
热门文章
- 从零开始学视觉Transformer (8):卷积和Transformer结合的ViT
- oracle用户新增数据文件,[数据库]20200722_Oracle添加表空间、用户,用户授权
- cancase vector_基于Vector总线设备的CAN总线测试方法概述
- matlab 排序点,matlab如何进行排序?
- org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException:
- 关系数据库——范式/反范式的利弊权衡和建议
- C语言:---gdb多线程调试
- Redis:05---键的基本命令(下) 生存周期
- 规范化流程化提交自己代码到远程gitlab服务器
- java蓝桥杯 试题-基础练习-数列排序