PKU1273 Drainage Ditches
2010-11-14 16:45
253 查看
网络流一道!
以前回的是SAP,估计现在让我写得卡死,于是我就把从前都不屑一顾的Edmonds-Karp试了一下。不就是一顿BFS么!我估计NOIP要考什么网络流也就这水平了…用不到什么SAP啦,HLPP什么的。当然模型也会很裸!
以前回的是SAP,估计现在让我写得卡死,于是我就把从前都不屑一顾的Edmonds-Karp试了一下。不就是一顿BFS么!我估计NOIP要考什么网络流也就这水平了…用不到什么SAP啦,HLPP什么的。当然模型也会很裸!
program ditch; const maxn=250; inf=10000000; var c:array[0..maxn,0..maxn] of longint; que,tmp,pre:array[0..maxn] of longint; n,m,delta,ans,head,tail:longint; procedure prework; begin ans:=0; fillchar(c,sizeof(c),0); end; procedure init; var i,a,b,w:longint; begin readln(m,n); for i:=1 to m do begin readln(a,b,w); inc(c[a,b],w); end; end; function getmin(a,b:longint):longint; begin if a<b then exit(a); exit(b); end; function bfs(s,t:longint):boolean; var u,v:longint; begin while head<tail do begin inc(head); u:=que[head]; for v:=1 to n do if (tmp[v]=0) and (c[u,v]>0) then begin inc(tail); que[tail]:=v; pre[v]:=u; tmp[v]:=getmin(tmp[u],c[u,v]); if v=t then begin delta:=tmp[v]; exit(true); end; end; end; exit(false); end; procedure modify(s,t:longint); var u,v:longint; begin inc(ans,delta); v:=t; u:=pre[v]; repeat dec(c[u,v],delta); inc(c[v,u],delta); v:=u; u:=pre[u]; until v=s; end; procedure ek(s,t:longint); begin while true do begin fillchar(tmp,sizeof(tmp),0); que[1]:=s; tmp[s]:=inf; head:=0; tail:=1; delta:=inf; if not bfs(s,t) then break; modify(s,t); end; end; procedure outit; begin writeln(ans); end; begin assign(input,'a.in'); reset(input); assign(output,'a.out'); rewrite(output); while not eof do begin prework; init; ek(1,n); outit; end; close(input); close(output); end.
相关文章推荐
- pku 1273
- pku 1273_Drainage Ditches 最大流问题
- hdu1532 & pku1273 Drainage Ditches 网络流(最大流EK算法)
- pku1273 Drainage Ditches
- 网络流入门----pku1273
- pku 1273 Drainage Ditches 最大流入门基础题
- PKU 1273 Drainage Ditches
- PKU-1273 Drainage Ditches (网络最大流)
- pku1273 Drainage Ditches
- PKU 1273 Drainage Ditches
- pku 1273 Drainage Ditches( Edmond-Karp最大流模板)
- 最大流裸题——pku1273
- 最大流问题 pku 1273 Drainage Ditches
- PKU 2774 Long Long Message
- pku 3694 Network
- pku3685 二分
- pku 3259Wormholes
- 矩阵乘法 pku 3233 Matrix Power Series hdu 1757 A Simple Math Problem fzu 1683 纪念SlingShot hdu 3306 Another kind of Fibonacc
- hdu1513 pku 1159Palindrome
- pku 3308 最小点权覆盖