bzoj1001 spfa
来源:互联网 发布:淘宝联盟旧版本5.2 编辑:程序博客网 时间:2024/05/19 17:49
const maxn=2000009; var s,t,n,m,e:longint; last,d,state:array[0..maxn] of longint; side:array[1..maxn*3] of record x,y,z,next:longint; end; v:array[0..maxn] of boolean; flag:boolean; procedure add(x,y,z:longint); begin inc(e); side[e].x:=x; side[e].y:=y; side[e].z:=z; side[e].next:=last[x]; last[x]:=e; inc(e); side[e].x:=y; side[e].y:=x; side[e].z:=z; side[e].next:=last[y]; last[y]:=e; end; procedure init; var i,j,ans,x:longint; begin ans:=maxlongint; readln(n,m); flag:=true; if (n=1)or(m=1) then flag:=false; if (n=1)and(m=1) then begin writeln(0); exit; end; if n=1 then begin for i:=1 to m-1 do begin read(x); if x<ans then ans:=x; end; writeln(ans); exit; end; if m=1 then begin for i:=1 to n-1 do begin read(x); if x<ans then ans:=x; end; writeln(ans); exit; end; s:=0; t:=2*(n-1)*(m-1)+1; for i:=1 to m-1 do begin read(x); add(i*2,t,x); end; for i:=2 to n-1 do for j:=1 to m-1 do begin read(x); add(2*(i-1)*(m-1)+j*2,2*(i-2)*(m-1)+j*2-1,x); end; for i:=1 to m-1 do begin read(x); add(s,2*(n-2)*(m-1)+i*2-1,x) end; for i:=1 to n-1 do begin read(x); add(s,2*(i-1)*(m-1)+1,x); for j:=2 to m-1 do begin read(x); add(2*(i-1)*(m-1)+2*j-1,2*(i-1)*(m-1)+2*(j-1),x); end; read(x); add(t,2*(i-1)*(m-1)+2*m-2,x); end; for i:=1 to n-1 do for j:=1 to m-1 do begin read(x); add(2*(i-1)*(m-1)+2*j-1,2*(i-1)*(m-1)+2*j,x); end; end; procedure spfa; var head,tail,i,u:longint; begin fillchar(d,sizeof(d),$7f div 3); d[s]:=0; fillchar(v,sizeof(v),true); v[s]:=false; head:=0; tail:=1; state[1]:=s; repeat inc(head); if head>t+7 then head:=1; u:=state[head]; i:=last[u]; while i>0 do with side[i] do begin if d[x]+z<d[y] then begin d[y]:=d[x]+z; if v[y] then begin v[y]:=false; inc(tail); if tail>t+7 then tail:=1; state[tail]:=y; end; end; i:=next; end; v[u]:=true; until head=tail; writeln(d[t]); end; begin init; if flag then spfa; end.
0 0
- bzoj1001 spfa
- BZOJ1001
- BZOJ1001
- bzoj1001
- bzoj1001
- bzoj1001
- BZOJ1001 狼抓兔子 详解 (平面图 spfa)
- BZOJ1001(BeiJing2006)[狼抓兔子]题解--最小割&spfa
- bzoj1001 [BeiJing2006]狼抓兔子(网络流dinic算法||最短路spfa)
- BZOJ1001题解
- SPFA
- spfa
- spfa
- SPFA
- SPFA
- SPFA
- SPFA
- spfa
- MapReduce实现KMeans
- 阿里巴巴温少写的 Maven整合SpringMVC+Spring+Hibernate pom.xml
- Android使用百度地图SDK实现定位功能
- 数据结构mooc学习
- 设计模式 策略模式 以角色游戏为背景
- bzoj1001 spfa
- Angular2的模块架构浅谈
- XML DOM 介绍
- 状态模式&策略模式
- 搭建lnmp、lamp架构环境
- Semaphore
- 文章标题
- 流感传染(C程序设计进阶 第2周)
- 关于多线程