【BZOJ】3396: [Usaco2009 Jan]Total flow 水流 (最大流)
http://www.lydsy.com/JudgeOnline/problem.php?id=3396
裸的最大流跑过。。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; }const int N=105, Q=N*100, oo=~0u>>1;
int ihead[N+10], cnt=1, n, gap[N+10], d[N+10], cur[N+10], p[N+10];
struct ED { int from, to, next, cap; }e[Q];
void add(int u, int v, int c) {e[++cnt].next=ihead[u]; ihead[u]=cnt; e[cnt].to=v; e[cnt].from=u; e[cnt].cap=c;e[++cnt].next=ihead[v]; ihead[v]=cnt; e[cnt].to=u; e[cnt].from=v; e[cnt].cap=0;
}
int get() {int t=0;char ch=getchar(); while(!(ch>='A'&&ch<='Z')&&!(ch>='a'&&ch<='z')) ch=getchar();if(ch>='A'&&ch<='Z') t=27+ch-'A';else t=ch-'a'+1;return t;
}int isap() {for1(i, 1, N) cur[i]=ihead[i];gap[0]=N;int s=27, t=27+'Z'-'A', u=s, i, flow=0, f;while(d[s]<N) {for(i=cur[u]; i; i=e[i].next) if(d[u]==d[e[i].to]+1 && e[i].cap) break;if(i) {p[e[i].to]=i; cur[u]=i; u=e[i].to;if(u==t) {for(f=oo; u!=s; u=e[p[u]].from) f=min(f, e[p[u]].cap);for(u=t; u!=s; u=e[p[u]].from) e[p[u]].cap-=f, e[p[u]^1].cap+=f;flow+=f;}}else {if(!(--gap[d[u]])) break;d[u]=N;cur[u]=ihead[u];for(i=ihead[u]; i; i=e[i].next) if(e[i].cap && d[u]>d[e[i].to]+1) d[u]=d[e[i].to]+1;++gap[d[u]];if(u!=s) u=e[p[u]].from;}}return flow;
}int main() {read(n);for1(i, 1, n) {int u=get(), v=get(), c=getint();add(u, v, c);}int ans=isap();if(ans==oo) puts("-1");else print(ans);return 0;
}
Description
Input
第1行输入N,之后N行每行描述一条水管,前两个英文字母表示水管的两端(大小写字母是不一样的),后一个整数表示水管的流量,流量不会超过1000.
Output
一个整数,表示总流量.
Sample Input
A B 3
B C 3
C D 5
D Z 4
B Z 6
Sample Output
HINT
Source
Silver
【BZOJ】3396: [Usaco2009 Jan]Total flow 水流 (最大流)相关推荐
- bzoj 3396: [Usaco2009 Jan]Total flow 水流(最大流)
3396: [Usaco2009 Jan]Total flow 水流 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 615 Solved: 295 ...
- bzoj 3396 [Usaco2009 Jan]Total flow 水流
Input 第1行输入N,之后N行每行描述一条水管,前两个英文字母表示水管的两端(大小写字母是不一样的),后一个整数表示水管的流量,流量不会超过1000. Output 一个整数,表示总流量. Sam ...
- bzoj3396[Usaco2009 Jan]Total flow 水流*
bzoj3396[Usaco2009 Jan]Total flow 水流 题意: 求无环图的最大流.边数≤700. 题解: 管它有没有环.注意本题的节点标号既有大写字母,也有小写字母. 代码: 1 # ...
- [BZOJ3396][Usaco2009 Jan]Total flow 水流(最大流)
题目描述 传送门 题解 最大流裸题. 代码 #include<iostream> #include<cstring> #include<cstdio> #inclu ...
- bzoj 3394: [Usaco2009 Jan]Best Spot 最佳牧场(floyd)
3394: [Usaco2009 Jan]Best Spot 最佳牧场 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 98 Solved: 76 [ ...
- 1574: [Usaco2009 Jan]地震损坏Damage
1574: [Usaco2009 Jan]地震损坏Damage Time Limit: 10 Sec Memory Limit: 64 MB Submit: 425 Solved: 232 [Su ...
- 解题报告 之 SOJ3353 Total Flow
解题报告 之 SOJ3353 Total Flow Description Time Limit: 2000 MS Memory Limit: 65536 K The Problem PROBLEM ...
- OpenFlow协议Open Flow交换机跟流表(FlowTable)
Open Flow协议.Open Flow交换机跟流表(FlowTable) 传统网络:传统网络的缺陷或者催生SDN的背景请参考链接https://www.cnblogs.com/031602523l ...
- Floodlight 用Static Flow Pusher 改变流表规则
实验拓扑: ==================================================================================== 1.登录minin ...
最新文章
- wps android qq 群,手机WPS怎样发送文档给QQ?WPS怎样发送文档给QQ教程
- php 画布插入图像,javascript – 如何在PHP中将html5画布图像保存到数据库
- ExtJS中给Tree节点加click事件
- 使用 Elasticsearch 优雅搭建自己的搜索系统
- Facade(外观模式)
- javascript函数调用的各种方法!!
- PAT甲题题解-1091. Acute Stroke (30)-BFS
- 论肱二头肌在日常生活中的锻炼的持久战|健身达人
- ado.net EF学习系列----深入理解查询延迟加载技术(转载)
- 趋势OFFICESCAN忘记卸载密码时如何卸载客户端
- 熟练的mescroll
- 数学模板-欧几里德算法扩展欧几里德算法
- 苏州珠宝玉石展览教您鉴别方法
- Linux那些事儿之我是U盘(16)冰冻三尺非一日之寒
- JAVA语言基础知识总结
- android studio导入音乐文件,Android Studio 通过raw 文件夹播放音乐问题
- 值得反复研读的表连接之CARTESIAN JOIN方式
- No valid crumb was included in the request
- Docker从入门到干活,看这一篇够了!
- sql查询取第一条数据
热门文章
- 微软正式发布PowerShell Core 6.0
- C语言中的static 具体分析
- Gentle.NET Attribute
- 修改url 参数_SEO优化设计,如何处理网址的动态参数?
- Use a production WSGI server instead(搭建web网站出现的问题)
- PyTorch学习笔记(三):PyTorch主要组成模块
- 即席查询Presto
- 面试题01.02 判定是否互为字符重排
- java学习(六)多线程 下
- 图像处理、分析与机器视觉(基于labview)_基于3D技术的机器视觉解决方案