iliya785

negative_cycle.Floyd

May 22nd, 2012
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.41 KB | None | 0 0
  1. var w:array[1..100,1..100] of longint;
  2.     i,j,n,k:longint;
  3.     negative_cycle:boolean;
  4. function min(a,b:longint):longint;
  5.  begin
  6.   if a < b then min:=a else min:=b;
  7.  end;
  8. Begin
  9. read(n);
  10. for i:=1 to n do
  11.  for j:=1 to n do
  12.   read(w[i][j]);
  13. for k:=1 to n do
  14.  for i:=1 to n do
  15.   for j:=1 to n do
  16.    w[i][j]:=min(w[i][j],w[i][k]+w[k][j]);
  17. for i:=1 to n do if w[i][i] < 0 then negative_cycle:=true;
  18. end.
Advertisement
Add Comment
Please, Sign In to add comment