Pascal classic algorithm - shortest path, labeling method to solve the shortest path of a single source point

From , 5 Years ago, written in Delphi (Object Pascal), viewed 208 times.
URL https://pastebin.vip/view/f1a94cef
  1. var
  2.   a: array[1..maxn, 1..maxn] of Integer;
  3.   b: array[1..maxn] of Integer; {b[i]指顶点i到源点的最短路径}
  4.   mark: array[1..maxn] of Boolean;
  5.  
  6. procedure bhf;
  7. var
  8.   best, best_j: Integer;
  9. begin
  10.   FillChar(mark, SizeOf(mark), false);
  11.   mark[1] := true;
  12.   b[1] := 0;{1为源点}
  13.   repeat
  14.     best := 0;
  15.     for i := 1 to n do
  16.       if mark[i] then {对每一个已计算出最短路径的点}
  17.         for j := 1 to n do
  18.           if (not mark[j]) and (a[i, j] > 0) then
  19.             if (best = 0) or (b[i] + a[i, j] < best) then
  20.             begin
  21.               best := b[i] + a[i, j];
  22.               best_j := j;
  23.             end;
  24.     if best > 0 then
  25.     begin
  26.       b[best_j] := best;mark[best_j] := true;
  27.     end;
  28.   until best = 0;
  29. end;
  30. //delphi/6606

Reply to "Pascal classic algorithm - shortest path, labeling method to solve the shortest path of a single source point"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website