Cod sursa(job #387687)

Utilizator mimarcelMoldovan Marcel mimarcel Data 28 ianuarie 2010 10:12:07
Problema Algoritmul lui Dijkstra Scor 90
Compilator fpc Status done
Runda Arhiva educationala Marime 0.91 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;
    vx,vy:word;
    vcost:longint;
    ok:boolean;
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
  begin
  readln(vx,vy,vcost);
  with g[i] do
    begin
    x:=vx;
    y:=vy;
    cost:=vcost;
    end;
  if vx=1 then c[vy]:=vcost;
  end;
repeat
ok:=true;
for i:=1 to m do
  begin
  vy:=g[i].y;
  vcost:=c[g[i].x]+g[i].cost;
  if c[vy]>vcost then
    begin
    c[vy]:=vcost;
    ok:=false;
    end;
  end;
until ok;
for i:=2 to n do
  if c[i]=mymax then write('0 ')
                else write(c[i],' ');
close(output);
close(input);
end.