其他分享
首页 > 其他分享> > Dijkstra

Dijkstra

作者:互联网

原文链接:http://www.cnblogs.com/lexluthor/archive/2012/01/06/2314983.html
 1 var i,j,n,s,t,p,min:longint;
2 a:array[1..1000,1..1000]of longint;
3 d:array[1..1000]of longint;
4 v:array[1..1000]of boolean;
5
6
7
8 procedure dijkstra(s:longint);
9 begin
10 fillchar(d,sizeof(d),$7f);
11 fillchar(v,sizeof(v),false);
12 d[s]:=0;
13 for j:=2 to n do begin
14 min:=maxlongint;
15 for i:=1 to n do
16 if (not v[i])and(d[i]<min) then begin
17 p:=i; min:=d[i];
18 end;
19 v[p]:=true;
20 for i:=1 to n do
21 if (not v[i])and(a[p,i]<>0)and
22 (d[p] a[p,i]<d[i]) then d[i]:=d[p] a[p,i];
23 end;
24 end;
25
26
27
28 begin
29 readln(n);
30 for i:=1 to n do
31 for j:=1 to n do read(a[i,j]);
32 readln(s,t);
33 dijkstra(s);
34 writeln(d[t]);
35 end.

转载于:https://www.cnblogs.com/lexluthor/archive/2012/01/06/2314983.html

标签:end,..,min,longint,Dijkstra,array,1000
来源: https://blog.csdn.net/weixin_30355437/article/details/98330131