var n,m:integer; g:array[1..150,1..150] of integer; v,mv:integer; best:array [1..150,0..1] of double; {dijkstra} i,j,p1,p2:integer; nmin:real; min:array [1..150,0..1] of double; vis:array [1..150,0..1] of boolean; procedure debugmin; var i,j:integer; begin for i:=0 to 1 do begin for j:=1 to 4 do begin write(min[j,i]:5:0); write('':5); end; writeln; end; writeln; end; procedure outp; begin assign(output,'output.txt'); rewrite(output); writeln(best[n,1]:0:2); close(output); end; procedure dijkstra; begin fillchar(vis,sizeof(vis),false); vis[1,0]:=true; vis[1,1]:=true; for i:=2 to n do begin if g[1,i]<>0 then begin min[i,0]:=g[1,i]/v; min[i,1]:=g[1,i]/mv; end else begin min[i,0]:=1e10; min[i,1]:=1e10; end; end; debugmin; while vis[n,1]=false do begin nmin:=1e10; for i:=0 to 1 do begin for j:=1 to n do begin if not vis[j,i] and (min[j,i]<nmin) then begin nmin:=min[j,i]; p1:=i; p2:=j; end;{end of if} end;{end of for} {选出最短的路径,并记录p1,p2} end; vis[p2,p1]:=true; best[p2,p1]:=nmin; writeln('choose: ',p2,p1); if p1=0 then begin for i:=1 to n do begin if not vis[i,0] and (min[i,0]>min[p2,0]+g[p2,i]/v) and (g[p2,i]<>0) then begin min[i,0]:=min[p2,0]+g[p2,i]/v; debugmin; end;{end of if} end; for i:=1 to n do begin if not vis[i,1] and (min[i,1]>min[p2,0]+g[p2,i]/mv) and (g[p2,i]<>0) then begin min[i,1]:=min[p2,0]+g[p2,i]/mv; debugmin; end;{end of if} end; end{end of if} {更新未加速的路径} else begin for i:=1 to n do begin if not vis[i,1] and (min[i,1]>min[p2,1]+g[p2,i]/v) and (g[p2,i]<>0) then begin min[i,1]:=min[p2,1]+g[p2,i]/v; debugmin; end; end;{end of for} end;{end of else} end;{end of while} end; procedure init; var i:integer; t1,t2,t3:integer; begin assign(input,'hole.txt'); reset(input); fillchar(g,sizeof(g),0); read(n,m); for i:=1 to m do begin read(t1,t2,t3); if(g[t1,t2]=0) or (g[t1,t2]>t3) then begin g[t1,t2]:=t3; g[t2,t1]:=t3; end; end; read(v,mv); end; {main} begin init; dijkstra; outp; end.
版权声明:本文为博主原创文章,未经博主允许不得转载。