Cod sursa(job #404600)

Utilizator andreispyesandrei fonoage andreispyes Data 26 februarie 2010 12:54:01
Problema Algoritmul Bellman-Ford Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 0.81 kb
const nodmax=50002;
      mucmax=250002;
      inf=2000000000;
type muchie=record
    X,Y,cost:longint;
    end;
var e:array [1..mucmax] of muchie;
    d:array [1..nodmax] of longint;
    i,j,m,n:longint;
    ok:boolean;
begin
    assign(input,'Bellmanford.in');
    reset(input);
    assign(output,'Bellmanford.out');
    rewrite(output);
    readln(n,m);
    for i := 2 to n do d[i]:=inf;


    for i := 1 to m do
     read(e[i].x,e[i].y,e[i].cost);

    repeat
        ok:=false;
        for i := 1 to m  do
                If d[e[i].y]>d[e[i].x]+e[i].cost then  begin
                        d[e[i].y]:=d[e[i].x]+e[i].cost;
                        ok:=true;
                        end;

    until ok=false;
    for i:=2 to n  do write(d[i],' ');

    close(input);
    close(output);

end.