Advertisement
Dennnhhhickk

Untitled

Sep 18th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. program Project1;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6. SysUtils;
  7.  
  8. const
  9. MAXIN = 2000;
  10. INF = 100000000000;
  11.  
  12. var
  13. n, s, f, i, j, ind, u, m, x, y, data: integer;
  14. a: array [1..MAXIN, 1..MAXIN] of int64;
  15. d, mark, b: array [1..MAXIN] of int64;
  16. min: int64;
  17.  
  18. function min1(a1, b1: int64): int64;
  19. begin
  20. if (a1 < b1) then
  21. min1 := a1
  22. else
  23. min1 := b1
  24. end;
  25.  
  26. begin
  27. readln(n, m, s, f);
  28.  
  29. for i := 1 to n do
  30. begin
  31. mark[i] := 0;
  32. d[i] := INF;
  33. b[i] := 0;
  34. end;
  35.  
  36. for i := 1 to m do
  37. for j := 1 to m do
  38. a[i][j] := 0;
  39.  
  40. For i := 1 to n do
  41. begin
  42. Readln(b[i]);
  43.  
  44. If (b[i] = 0) then
  45.  
  46. B[i] := INF;
  47.  
  48. end;
  49.  
  50. for i := 1 to m do
  51. begin
  52. readln(x, y, data);
  53. a[x][y] := data;
  54. a[y][x] := data;
  55. end;
  56.  
  57. d[s] := 0;
  58.  
  59. while (true) do
  60. begin
  61. ind := -1;
  62. min := INF;
  63. for i := 1 to m do
  64. if ((mark[i] = 0) and (d[i] <= min)) then
  65. begin
  66. ind := i;
  67. min := d[i];
  68. end;
  69. if (ind = -1) then
  70. break;
  71. mark[ind] := 1;
  72. For u := 1 to n do
  73. If (a[ind, u] <> 0) and (d[ind] + a[ind, u] < b[u]) then
  74. D[u] := min1(d[u], d[ind] + a[ind, u]);
  75. end;
  76.  
  77. if (d[f] <> INF) then
  78. writeln(d[f])
  79. else
  80. writeln(-1);
  81.  
  82. readln;
  83. readln;
  84.  
  85. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement