Cod sursa(job #386594)

Utilizator mimarcelMoldovan Marcel mimarcel Data 25 ianuarie 2010 12:39:04
Problema Algoritmul lui Dijkstra Scor 90
Compilator fpc Status done
Runda Arhiva educationala Marime 0.8 kb
type muchie=record
            x,y,cost:word;
            end;
const nmax=50000;
      mmax=250000;
      mymax=maxlongint div 2;
var n:word;
    m,i:longint;
    g:array[1..mmax]of muchie;
    c:array[1..nmax]of longint;
    ok:byte;
begin
assign(input,'dijkstra.in');
reset(input);
assign(output,'dijkstra.out');
rewrite(output);
filldword(c,sizeof(c)div 4,mymax);
c[1]:=0;
readln(n,m);
for i:=1 to m do
  with g[i] do
    begin
    readln(x,y,cost);
    if x=1 then c[y]:=cost;
    end;
repeat
ok:=0;
for i:=1 to m do
  begin
  if c[g[i].y]>c[g[i].x]+g[i].cost then
    begin
    c[g[i].y]:=c[g[i].x]+g[i].cost;
    ok:=255;
    end;
  end;
until ok<128;
for i:=2 to n do
  if c[i]=mymax then write('0 ')
                else write(c[i],' ');
close(output);
close(input);
end.