Pagini recente » Cod sursa (job #2012169) | Istoria paginii utilizator/levladutz | Istoria paginii runda/andrei_boaca_will_win_ioi2022 | Istoria paginii utilizator/mihaipriboi | Cod sursa (job #255764)
Cod sursa(job #255764)
const inf=2000000000;
const nmax=1501;
type lista=^elem;
elem=record
v,c:longint;
adu:lista;
end;
var poz,d,viz:array[1..nmax] of longint;
a:array[1..nmax] of lista;
c:array[1..4*nmax]of longint;
q:lista;
f,g:text;
min,ct,i,j,x,pc,uc,y,n,m:longint;
ok:boolean;
begin
assign(f,'dmin.in');
reset(f);
assign(g,'dmin.out');
rewrite(g);
readln(f,n,m);
for i:=1 to m do
begin
readln(f,x,y,ct);
new(q);
q^.c:=ct;
q^.v:=y;
q^.adu:=a[x];
a[x]:=q;
end;
for i:=2 to n do
begin
d[i]:=inf;
{ poz[i]:=1; }
end;
q:=a[1];
while q<>NIL do
begin
d[q^.v]:=q^.c;
poz[q^.v]:=1;
q:=q^.adu;
end;
d[1]:=1;
poz[1]:=1;
pc:=1;
uc:=1;
c[pc]:=1;
viz[1]:=1;
repeat
ok:=false;
min:=inf;
for i:=1 to n do
if (viz[i]=0) and (d[i]<min) then
begin
min:=d[i];
y:=i;
ok:=true;
end;
if ok then
begin
viz[y]:=1;
q:=a[y];
while q<>Nil do
begin
if viz[q^.v]=0 then
begin
if d[q^.v]>d[y]+q^.c then
begin
d[q^.v]:=d[y]+q^.c;
poz[q^.v]:=poz[y];
end
else if d[q^.v]=d[y]+q^.c then
poz[q^.v]:=poz[q^.v]+poz[y];
end;
q:=q^.adu;
end;
end;
until not ok;
while pc<=uc do
begin
q:=a[c[pc]];
while q<>NIL do
begin
if (q^.c*d[c[pc]])<d[q^.v] then
begin
poz[q^.v]:=poz[c[pc]];
d[q^.v]:=q^.c*d[c[pc]];
if viz[q^.v]=0 then
begin
uc:=uc+1;
c[uc]:=q^.v;
viz[q^.v]:=1;
end;
end
else if (q^.c*d[c[pc]])=d[q^.v] then
poz[q^.v]:=poz[q^.v]+poz[c[pc]];
q:=q^.adu;
end;
viz[c[pc]]:=0;
pc:=pc+1;
end;
for i:=2 to n do
begin
write(g,(poz[i]mod 104659),' ');
end;
close(g);
end.