Pagini recente » Cod sursa (job #1396498) | Cod sursa (job #69724) | Cod sursa (job #2454034) | Cod sursa (job #1251381) | Cod sursa (job #404600)
Cod sursa(job #404600)
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.