标签:
1 program dijkstra; 2 var 3 a:array[1..100,1..100]of integer; 4 flag:array[1..100]of boolean; 5 w,x,n,i,j,min,minn:integer; 6 begin 7 readln(n); 8 for i:=1 to n do 9 for j:=1 to n do 10 read(a[i,j]); 11 fillchar(flag,sizeof(flag),false); 12 flag[1]:=true; 13 minn:=1; 14 for x:=2 to n do 15 begin 16 min:=maxint; 17 for i:=2 to n do 18 if (a[1,i]<min)and(flag[i]=false) then 19 begin 20 min:=a[1,i]; 21 minn:=i; 22 end; 23 flag[minn]:=true; 24 for j:=1 to n do 25 if (j<>minn) and (a[1,minn]+a[minn,j]<a[1,j]) and(flag[j]=false) then 26 a[1,j]:=a[1,minn]+a[minn,j]; 27 end; 28 for i:=1 to n do 29 write(a[1,i],‘ ‘); 30 end.
标签:
原文地址:http://www.cnblogs.com/OmegaIota/p/4395243.html