BZOJ3396: [Usaco2009 Jan]Total flow 水流
3396: [Usaco2009 Jan]Total flow 水流
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 45 Solved: 27
[Submit][Status]
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
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 200
#define maxm 1500
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int n,m,s,t,maxflow,tot=,head[maxn],cur[maxn],h[maxn],q[maxn];
struct edge{int go,next,v;}e[maxm];
void ins(int x,int y,int z){e[++tot].go=y;e[tot].v=z;e[tot].next=head[x];head[x]=tot;}
void insert(int x,int y,int z){ins(x,y,z);ins(y,x,);}
bool bfs()
{
for(int i=;i<=;i++)h[i]=-;
int l=,r=;q[]=s;h[s]=;
while(l<r)
{
int x=q[++l];
for(int i=head[x];i;i=e[i].next)
if(e[i].v&&h[e[i].go]==-)
{
h[e[i].go]=h[x]+;q[++r]=e[i].go;
}
}
return h[t]!=-;
}
int dfs(int x,int f)
{
if(x==t) return f;
int tmp,used=;
for(int i=head[x];i;i=e[i].next)
if(e[i].v&&h[e[i].go]==h[x]+)
{
tmp=dfs(e[i].go,min(e[i].v,f-used));
e[i].v-=tmp;if(e[i].v)cur[x]=i;
e[i^].v+=tmp;used+=tmp;
if(used==f)return f;
}
if(!used) h[x]=-;
return used;
}
void dinic()
{
maxflow=;
while(bfs())
{
for (int i=s;i<=t;i++)cur[i]=head[i];maxflow+=dfs(s,inf);
}
}
inline int get()
{
char ch=' ';
while((ch<'a'||ch>'z')&&(ch<'A'||ch>'Z'))ch=getchar();
return ch;
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();
for1(i,n)
{
int x=get(),y=get(),z=read();
insert(x,y,z);
}
s=(int)'A';t=(int)'Z';
dinic();
printf("%d\n",maxflow);
return ;
}
BZOJ3396: [Usaco2009 Jan]Total flow 水流的更多相关文章
- 【网络流】【Dinic】【最大流】bzoj3396 [Usaco2009 Jan]Total flow 水流
#include<cstdio> #include<cstring> #include<algorithm> #include<queue> using ...
- 3396: [Usaco2009 Jan]Total flow 水流
3396: [Usaco2009 Jan]Total flow 水流 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 179 Solved: 73[Su ...
- 【BZOJ】3396: [Usaco2009 Jan]Total flow 水流 (最大流)
http://www.lydsy.com/JudgeOnline/problem.php?id=3396 裸的最大流跑过.. #include <cstdio> #include < ...
- bzoj 3396: [Usaco2009 Jan]Total flow 水流【最大流】
最大流生动形象的板子,注意数组开大点 #include<iostream> #include<cstdio> #include<queue> #include< ...
- bzoj 1576: [Usaco2009 Jan]安全路经Travel 树链剖分
1576: [Usaco2009 Jan]安全路经Travel Time Limit: 10 Sec Memory Limit: 64 MB Submit: 665 Solved: 227[Sub ...
- BZOJ3394: [Usaco2009 Jan]Best Spot 最佳牧场
3394: [Usaco2009 Jan]Best Spot 最佳牧场 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 11 Solved: 9[Sub ...
- 1574: [Usaco2009 Jan]地震损坏Damage
1574: [Usaco2009 Jan]地震损坏Damage Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 425 Solved: 232[Subm ...
- 2018.07.06 洛谷P2936 [USACO09JAN]全流Total Flow(最大流)
P2936 [USACO09JAN]全流Total Flow 题目描述 Farmer John always wants his cows to have enough water and thus ...
- 洛谷——P2936 [USACO09JAN]全流Total Flow
题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 < ...
随机推荐
- SheetOffice控件使用分享
1. 控件属性及说明 Template:套用的模板目录(套用模板会使用到) 模板中必须包含书签: Body,这个是在代码中写死了的,是把当前文档的内容插入到模板的Body书签中. 如果使用印章,必须 ...
- SKPhysicsJointFixed类
继承自 NSObject 符合 NSCoding(SKPhysicsJoint)NSObject(NSObject) 框架 /System/Library/Frameworks/SpriteKit. ...
- JMeter在里面Json数据处理方法
http://eclipsesource.com/blogs/2014/06/12/parsing-json-responses-with-jmeter/ Json作为一种数据交换格式在网络开发.特别 ...
- Java 编程的动态性,第 7 部分: 用 BCEL 设计字节码--转载
在本系列的最后三篇文章中,我展示了如何用 Javassist 框架操作类.这次我将用一种很不同的方法操纵字节码——使用 Apache Byte Code Engineering Library (BC ...
- Java – 4 Security Vulnerabilities Related Coding Practices to Avoid---reference
This article represents top 4 security vulnerabilities related coding practice to avoid while you ar ...
- Java基础知识强化70:正则表达式之引入案例(QQ号码校验)
1. 校验QQ号码的案例,如下: package cn.itcast_01; import java.util.Scanner; /* * 校验qq号码. * 1:要求必须是5-15位数字 * 2:0 ...
- SharedPreferences的工具类,使用起来方便、快捷
SharedPreferences的工具类,使用起来方便.快捷:上代码:import android.content.Context;import android.content.SharedPref ...
- Windows Media Player Plus
Windows Media Player Plus 是一款 Windows Media Player 的插件,提供很多实用功能,Mark 一下.
- asp.net微信开发第七篇----高级群发(图文)
上一篇介绍了如何群发文本消息,本篇将介绍如何群发图文信息,上传图文信息所需的素材,界面如下: 我们先看从素材库中获取图文素材的代码,界面: 素材列表,我是使用的repeater控件, 前台代码如下: ...
- MySQL慢查询详解
分析MySQL语句查询性能的方法除了使用 EXPLAIN 输出执行计划,还可以让MySQL记录下查询超过指定时间的语句,我们将超过指定时间的SQL语句查询称为“慢查询”. 查看/设置“慢查询”的时 ...