3396: [Usaco2009 jan]total Flow Flow

Source: Internet
Author: User

3396: [Usaco2009 jan]total Flow Current time limit:1 Sec Memory limit:128 MB
submit:179 solved:73
[Submit] [Status] Description Input

The 1th line enters N, and then each row of n lines describes a water pipe, and the first two letters indicate the two ends of the water pipe (the uppercase and lowercase letters are not the same), and the latter integer represents the flow of the water pipe, and the flow does not exceed 1000.

Output

An integer that represents the total traffic.

Sample INPUT5
A B 3
B C 3
C D 5
D Z 4
B Z 6Sample output3hint Source

Silver

Problem: WA took 6 times to read the question only to find the size of the letter is not the same as TT. Nothing else, go directly to SAP template A.

1 type2Point=^node;3Node=Record4 G,w:longint;5 Next,anti:point;6     End;7 var8 I,j,k,l,m,n,ans,s,t:longint;9A:Array[0.. -] ofPoint ;TenD,DV:Array[0.. -] ofLongint; One C1,c2,c3:char; A functionmin (x,y:longint): Longint;inline; -          begin -               ifX<y ThenMin:=xElsemin:=y; the          End; - procedureAdd (x,y,z:longint); inline; -           varP:point; -           begin +New (p);p ^.g:=y;p^.w:=z;p^.next:=a[x];a[x]:=p; -New (p);p ^.g:=x;p^.w:=0;p ^.next:=a[y];a[y]:=p; +a[y]^.anti:=a[x];a[x]^.anti:=A[y]; A           End; at functionDFS (x,flow:longint): Longint;inline; -          varP:point;k:longint; -          begin -               ifX=t Thenexit (flow); -dfs:=0;p: =A[x]; -                whileP<>Nil  Do in                     begin -                          if(p^.w>0) and(D[x]= (d[p^.g]+1)) Then to                             begin +K:=dfs (P^.g,min (p^.w,flow-Dfs)); - Dec (p^.w,k); the Inc (P^.ANTI^.W,K); * Inc (DFS,K); $                                  ifDfs=flow Thenexit;Panax Notoginseng                             End; -p:=P^.next; the                     End; +               ifD[s]=n Thenexit; A Dec (dv[d[x]]); the               ifdv[d[x]]=0  Thend[s]:=N; + Inc (D[x]); - Inc (Dv[d[x]); $          End; $ functionTrans (X:char): Longint;inline; -          begin -                CaseX of the                    'A'..'Z': Exit (Ord (x)-ord ('A')+1); -                    'a'..'Z': Exit (Ord (x)-ord ('a')+ -);Wuyi               End; the          End; - functionGetc:longint;inline; Wu          begin -               Repeat About read (C1); $               until(UpCase (C1) >='A') and(UpCase (C1) <='Z'); - exit (Trans (C1)); -          End; - begin AREADLN (m); n:= the; +       fori:=1  toN Doa[i]:=Nil; thes:=1; t:= -; -       fori:=1  toM Do $          begin thej:=getc;k:=getc;readln (l); the Add (j,k,l); the          End; theFillchar (d,sizeof (d),0); -Fillchar (Dv,sizeof (DV),0); indv[0]:=N; theans:=0; the       whileD[s]<n DoInc (Ans,dfs (S,maxlongint)); About writeln (ans); the End.

3396: [Usaco2009 jan]total Flow Flow

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.