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

5
A B 3
B C 3
C D 5
D Z 4
B Z 6

Sample Output

3

HINT

Source

Silver

【BZOJ】3396: [Usaco2009 Jan]Total flow 水流 (最大流)相关推荐

  1. bzoj 3396: [Usaco2009 Jan]Total flow 水流(最大流)

    3396: [Usaco2009 Jan]Total flow 水流 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 615  Solved: 295 ...

  2. bzoj 3396 [Usaco2009 Jan]Total flow 水流

    Input 第1行输入N,之后N行每行描述一条水管,前两个英文字母表示水管的两端(大小写字母是不一样的),后一个整数表示水管的流量,流量不会超过1000. Output 一个整数,表示总流量. Sam ...

  3. bzoj3396[Usaco2009 Jan]Total flow 水流*

    bzoj3396[Usaco2009 Jan]Total flow 水流 题意: 求无环图的最大流.边数≤700. 题解: 管它有没有环.注意本题的节点标号既有大写字母,也有小写字母. 代码: 1 # ...

  4. [BZOJ3396][Usaco2009 Jan]Total flow 水流(最大流)

    题目描述 传送门 题解 最大流裸题. 代码 #include<iostream> #include<cstring> #include<cstdio> #inclu ...

  5. bzoj 3394: [Usaco2009 Jan]Best Spot 最佳牧场(floyd)

    3394: [Usaco2009 Jan]Best Spot 最佳牧场 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 98  Solved: 76 [ ...

  6. 1574: [Usaco2009 Jan]地震损坏Damage

    1574: [Usaco2009 Jan]地震损坏Damage Time Limit: 10 Sec  Memory Limit: 64 MB Submit: 425  Solved: 232 [Su ...

  7. 解题报告 之 SOJ3353 Total Flow

    解题报告 之 SOJ3353 Total Flow Description Time Limit: 2000 MS Memory Limit: 65536 K The Problem PROBLEM ...

  8. OpenFlow协议Open Flow交换机跟流表(FlowTable)

    Open Flow协议.Open Flow交换机跟流表(FlowTable) 传统网络:传统网络的缺陷或者催生SDN的背景请参考链接https://www.cnblogs.com/031602523l ...

  9. Floodlight 用Static Flow Pusher 改变流表规则

    实验拓扑: ==================================================================================== 1.登录minin ...

最新文章

  1. wps android qq 群,手机WPS怎样发送文档给QQ?WPS怎样发送文档给QQ教程
  2. php 画布插入图像,javascript – 如何在PHP中将html5画布图像保存到数据库
  3. ExtJS中给Tree节点加click事件
  4. 使用 Elasticsearch 优雅搭建自己的搜索系统
  5. Facade(外观模式)
  6. javascript函数调用的各种方法!!
  7. PAT甲题题解-1091. Acute Stroke (30)-BFS
  8. 论肱二头肌在日常生活中的锻炼的持久战|健身达人
  9. ado.net EF学习系列----深入理解查询延迟加载技术(转载)
  10. 趋势OFFICESCAN忘记卸载密码时如何卸载客户端
  11. 熟练的mescroll
  12. 数学模板-欧几里德算法扩展欧几里德算法
  13. 苏州珠宝玉石展览教您鉴别方法
  14. Linux那些事儿之我是U盘(16)冰冻三尺非一日之寒
  15. JAVA语言基础知识总结
  16. android studio导入音乐文件,Android Studio 通过raw 文件夹播放音乐问题
  17. 值得反复研读的表连接之CARTESIAN JOIN方式
  18. No valid crumb was included in the request
  19. Docker从入门到干活,看这一篇够了!
  20. sql查询取第一条数据

热门文章

  1. 微软正式发布PowerShell Core 6.0
  2. C语言中的static 具体分析
  3. Gentle.NET Attribute
  4. 修改url 参数_SEO优化设计,如何处理网址的动态参数?
  5. Use a production WSGI server instead(搭建web网站出现的问题)
  6. PyTorch学习笔记(三):PyTorch主要组成模块
  7. 即席查询Presto
  8. 面试题01.02 判定是否互为字符重排
  9. java学习(六)多线程 下
  10. 图像处理、分析与机器视觉(基于labview)_基于3D技术的机器视觉解决方案