Pagini recente » Cod sursa (job #2370853) | Cod sursa (job #2095110) | Cod sursa (job #904543) | Cod sursa (job #1687024) | Cod sursa (job #186940)
Cod sursa(job #186940)
const inf = 1001;
type graf=^elem;
elem=record
info, cost : longint;
next : graf;
end;
lista=^list;
list=record
info : longint;
next : lista;
end;
var fi,fo : text;
n, m, ns, nf, i, j, k, tr : longint;
d : Array[1..250000]of longint;
v : Array[1..250000]of graf;
l, sf : Array[0..1000]of lista;
p : graf;
q, f : lista;
procedure qin(vl,ind:longint);
var p:lista;
begin
new(p);
p^.info:=vl;
p^.next:=nil;
if l[ind]=nil then
begin
l[ind]:=p;
sf[ind]:=l[ind];
exit;
end;
sf[ind]^.next:=p;
sf[ind]:=p;
end;
begin
assign(fi,'pscnv.in'); reset(fi);
assign(fo,'pscnv.out'); rewrite(fo);
read(fi,n,m,ns,nf);
for tr:=1 to m do
begin
read(fi,i,j,k);
new(p);
p^.info:=j;
p^.cost:=k;
p^.next:=v[i];
v[i]:=p;
end;
for i:=1 to n do
d[i]:=inf;
d[ns]:=0;
qin(ns,0);
for i:=0 to 1000 do
begin
q:=l[i];
while q<>nil do
begin
if d[q^.info]=i then
begin
p:=v[q^.info];
while p<>nil do
begin
if d[q^.info]>p^.cost then
if d[p^.info]>d[q^.info] then
begin
qin(p^.info,d[q^.info]);
d[p^.info]:=d[q^.info];
end;
if p^.cost>=d[q^.info] then
if d[p^.info]>p^.cost then
begin
qin(p^.info,p^.cost);
d[p^.info]:=p^.cost;
end;
p:=p^.next;
end;
end;
q:=q^.next;
end;
end;
writeln(fo,d[nf]);
close(fi);
close(fo);
end.