bzoj3396[Usaco2009 Jan]Total flow 水流*
bzoj3396[Usaco2009 Jan]Total flow 水流
题意:
求无环图的最大流。边数≤700。
题解:
管它有没有环。注意本题的节点标号既有大写字母,也有小写字母。
代码:
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <queue> 5 #define inc(i,j,k) for(int i=j;i<=k;i++) 6 #define maxn 100 7 #define INF 0x3fffffff 8 using namespace std; 9 10 struct e{int t,c,n;}es[maxn*80]; int g[maxn],ess; 11 void pe(int f,int t,int c){ 12 es[++ess]=(e){t,c,g[f]}; g[f]=ess; es[++ess]=(e){f,0,g[t]}; g[t]=ess; 13 es[++ess]=(e){f,c,g[t]}; g[t]=ess; es[++ess]=(e){t,0,g[f]}; g[f]=ess; 14 } 15 queue<int>q; int h[maxn]; 16 bool bfs(int s,int t){ 17 while(!q.empty())q.pop(); memset(h,-1,sizeof(h)); q.push(s); h[s]=0; 18 while(!q.empty()){ 19 int x=q.front(); q.pop(); 20 for(int i=g[x];i;i=es[i].n)if(es[i].c&&h[es[i].t]==-1){h[es[i].t]=h[x]+1; q.push(es[i].t);} 21 } 22 return h[t]!=-1; 23 } 24 int dfs(int x,int t,int f){ 25 if(x==t)return f; int u=0; 26 for(int i=g[x];i;i=es[i].n)if(es[i].c&&h[es[i].t]==h[x]+1){ 27 int w=dfs(es[i].t,t,min(f,es[i].c)); f-=w; u+=w; 28 es[i].c-=w; es[i^1].c+=w; if(f==0)return u; 29 } 30 if(u==0)h[x]=-1; return u; 31 } 32 int dinic(int s,int t){ 33 int f=0; while(bfs(s,t))f+=dfs(s,t,INF); return f; 34 } 35 int s,t,n; 36 int main(){ 37 scanf("%d",&n); ess=1; s=0; t='Z'-'A'; 38 inc(i,1,n){char x[3],y[3]; int z; scanf("%s%s%d",x,y,&z); pe(x[0]-'A',y[0]-'A',z);} 39 printf("%d",dinic(s,t)); return 0; 40 }
20160908
转载于:https://www.cnblogs.com/YuanZiming/p/5875540.html
bzoj3396[Usaco2009 Jan]Total flow 水流*相关推荐
- [BZOJ3396][Usaco2009 Jan]Total flow 水流(最大流)
题目描述 传送门 题解 最大流裸题. 代码 #include<iostream> #include<cstring> #include<cstdio> #inclu ...
- 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 水流 (最大流)
http://www.lydsy.com/JudgeOnline/problem.php?id=3396 裸的最大流跑过.. #include <cstdio> #include < ...
- bzoj 3396 [Usaco2009 Jan]Total flow 水流
Input 第1行输入N,之后N行每行描述一条水管,前两个英文字母表示水管的两端(大小写字母是不一样的),后一个整数表示水管的流量,流量不会超过1000. Output 一个整数,表示总流量. Sam ...
- 1574: [Usaco2009 Jan]地震损坏Damage
1574: [Usaco2009 Jan]地震损坏Damage Time Limit: 10 Sec Memory Limit: 64 MB Submit: 425 Solved: 232 [Su ...
- bzoj 3394: [Usaco2009 Jan]Best Spot 最佳牧场(floyd)
3394: [Usaco2009 Jan]Best Spot 最佳牧场 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 98 Solved: 76 [ ...
- 解题报告 之 SOJ3353 Total Flow
解题报告 之 SOJ3353 Total Flow Description Time Limit: 2000 MS Memory Limit: 65536 K The Problem PROBLEM ...
- 【BZOJ】1574: [Usaco2009 Jan]地震损坏Damage
[算法]搜索 [题意]给定无向图,现在可能有一些点已经被删除,只给出信息是c个点不能到达结点1,求最少的不能到达结点1的个数(含已删除点). [题解] 真是一道奥妙重重的题目. 每个点不能到达结点1, ...
- BZOJ3393 [Usaco2009 Jan]Laserphones 激光通讯
第一次知道..原来spfa还可以这样写...用pq... 只需要直接求拐点即可,数据小想怎么搞就怎么搞 (话说怎么这么裸的最短路都写不出来了233) 1 /********************** ...
最新文章
- 国际版Azure搭建Windows多种类型×××_三.配置SSTP ×××连接服务
- 车道检测--VPGNet: Vanishing Point Guided Network for Lane and Road Marking Detection and Recognition
- 加快促进大数据与实体经济深度融合发展
- 两个线程如何交替执行,一个输出偶数一个输出奇数?
- beoplay(BO)耳机拒绝配对的解决方法
- 慕课网:SpringBoot+MyBatis搭建迷你小程序
- 简明Vim练级攻略(转)
- 滑动拼图验证码操作步骤:_拼图项目:延期的后果
- 每帧只需9ms,手机实时「三维动作识别」
- 安装mysql8.0.11
- snap-社交网络分析
- 《大学物理》知识点总结
- 先进激光三维成像雷达技术的研究进展与趋势分析
- 井下各种压力概念及相互关系
- 嘘!捡漏啦!1919元=高性能电脑,满额+500京东卡...
- Tomcat开启为什么会秒退
- 旋转矩阵、欧拉角、旋转矢量及四元数的介绍和工程应用
- oracle新建用户并授权视图
- Logisim中文版 免JAVA环境 免安装
- 5G — Overview