3396: [Usaco2009 Jan]Total flow 水流

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 179  Solved: 73
[Submit][Status]

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

题解:WA了6次再读题才发现大小写字母不一样TT。别的没了,直接上sap模板A之。。

 type
point=^node;
node=record
g,w:longint;
next,anti:point;
end;
var
i,j,k,l,m,n,ans,s,t:longint;
a:array[..] of point;
d,dv:array[..] of longint;
c1,c2,c3:char;
function min(x,y:longint):longint;inline;
begin
if x<y then min:=x else min:=y;
end;
procedure add(x,y,z:longint);inline;
var p:point;
begin
new(p);p^.g:=y;p^.w:=z;p^.next:=a[x];a[x]:=p;
new(p);p^.g:=x;p^.w:=;p^.next:=a[y];a[y]:=p;
a[y]^.anti:=a[x];a[x]^.anti:=a[y];
end;
function dfs(x,flow:longint):longint;inline;
var p:point;k:longint;
begin
if x=t then exit(flow);
dfs:=;p:=a[x];
while p<>nil do
begin
if (P^.w>) and (d[x]=(d[p^.g]+)) then
begin
k:=dfs(p^.g,min(p^.w,flow-dfs));
dec(p^.w,k);
inc(p^.anti^.w,k);
inc(dfs,k);
if dfs=flow then exit;
end;
p:=p^.next;
end;
if d[s]=n then exit;
dec(dv[d[x]]);
if dv[d[x]]= then d[s]:=n;
inc(d[x]);
inc(dv[d[x]]);
end;
function trans(x:char):longint;inline;
begin
case x of
'A'..'Z':exit(ord(x)-ord('A')+);
'a'..'z':exit(ord(x)-ord('a')+);
end;
end;
function getc:longint;inline;
begin
repeat
read(c1);
until (upcase(c1)>='A') and (upcase(c1)<='Z');
exit(trans(c1));
end;
begin
readln(m);n:=;
for i:= to n do a[i]:=nil;
s:=;t:=;
for i:= to m do
begin
j:=getc;k:=getc;readln(l);
add(j,k,l);
end;
fillchar(d,sizeof(d),);
fillchar(dv,sizeof(dv),);
dv[]:=n;
ans:=;
while d[s]<n do inc(ans,dfs(s,maxlongint));
writeln(ans);
end.

3396: [Usaco2009 Jan]Total flow 水流的更多相关文章

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

    http://www.lydsy.com/JudgeOnline/problem.php?id=3396 裸的最大流跑过.. #include <cstdio> #include < ...

  2. bzoj 3396: [Usaco2009 Jan]Total flow 水流【最大流】

    最大流生动形象的板子,注意数组开大点 #include<iostream> #include<cstdio> #include<queue> #include< ...

  3. BZOJ3396: [Usaco2009 Jan]Total flow 水流

    3396: [Usaco2009 Jan]Total flow 水流 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 45  Solved: 27[Sub ...

  4. 【网络流】【Dinic】【最大流】bzoj3396 [Usaco2009 Jan]Total flow 水流

    #include<cstdio> #include<cstring> #include<algorithm> #include<queue> using ...

  5. bzoj 1576: [Usaco2009 Jan]安全路经Travel 树链剖分

    1576: [Usaco2009 Jan]安全路经Travel Time Limit: 10 Sec  Memory Limit: 64 MB Submit: 665  Solved: 227[Sub ...

  6. BZOJ3394: [Usaco2009 Jan]Best Spot 最佳牧场

    3394: [Usaco2009 Jan]Best Spot 最佳牧场 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 11  Solved: 9[Sub ...

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

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

  8. 2018.07.06 洛谷P2936 [USACO09JAN]全流Total Flow(最大流)

    P2936 [USACO09JAN]全流Total Flow 题目描述 Farmer John always wants his cows to have enough water and thus ...

  9. 洛谷——P2936 [USACO09JAN]全流Total Flow

    题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 < ...

随机推荐

  1. AIX上面Oracle数据库相关启动

    1,启动停止Oracle实例 (1) su -oracle (2) echo $ORACLE_SID (3) sqlplus /nolog //以不登录到数据库的方式进入sqlplus环境 (4) c ...

  2. 程序启动缓慢-原来是hbm.xml doctype的原因

    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "h ...

  3. Pomelo术语解释

    gate服务器 一个应用的gate服务器,一般不参与rpc调用,也就是说其配置项里可以没有port字段,仅仅有clientPort字段,它的作用是做前端的负载均衡.客户端往往首先向gate服务器发出请 ...

  4. 巧用css text-indent减小中文标点符号的占位大小

    由于设计需要,我们的页面中经常会有如下效果: 可是我们实现出来的效果确实这样的: 看起来两行文本没有对齐嘛,仔细检查后原来是[字符的原因,因为是中文标点符号占半个字的位置.不信?选中下汉字标点符号看一 ...

  5. TCP协议滑动窗口(一)——控制数据传输速率

    窗口大小:TCP头中一个16位的域,表示当前可用接受缓冲区大小.在每个TCP对等段连接初始化时,告诉对方自己的窗口大小(不一定是满额,假如满额65201字节,可能暂时通告5840字节).若客户端接受数 ...

  6. 详解googe Chrome浏览器(理论篇)

    开篇概述 1详解google Chrome浏览器,这个标题似乎抽象了一些,我想应该把它拆分成如下几个问题,也许会更加理解一些. 问题1:目前开发中,主选浏览器有Google Chrome,IE,Fir ...

  7. Div.2 C. Dasha and Password

    C. Dasha and Password time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  8. 快速入门Http协议

    本节主要讲解http协议相关的内容,作为后期讲述的一个预备知识.深入了解Http协议,对你今后的JavaSE,JavaEE学习都大有裨益,本节难度不是很大,却很重要. 早期的Http协议是1.0版本的 ...

  9. LoadRunner 调用Dll完成加密解密

    LoadRunner里的函数比较少,没有MD5.Base64加密. 我们可以通过在C++里把一些加解密写成函数,供LR调用. DLL函数编写 C++里新建工程Class Library(此处是用VS2 ...

  10. iOS深入学习之Weak关键字介绍

    iOS深入学习之Weak关键字介绍 前言 从大二的开始接触OC就用到了weak属性修饰词,但是当时只是知道如何去用这个关键字:防止循环引用.根本没有深入地去了解它. 在刚来北京的时候面试过程中也常常考 ...