const MaxN = 1000001;
var n,m,s,f:longint;
c,d,q,p:array[0..MaxN] of int64;
a,b,t,kq:array[0..MaxN] of longint;
procedure init;
var i,x,y:longint; z:int64;
begin
read(n,m,s,f);
for i:=1 to m do
begin
read(x,y,z);
a[i]:=x; b[i]:=y; c[i]:=z;
a[i+m]:=y; b[i+m]:=x; c[i+m]:=z;
end;
end;
procedure sort(l,r:longint);
var i,j,x:longint; y:int64;
begin
i:=l; j:=r; x:=a[(i+j) div 2];
repeat
while a[i]<x do inc(i);
while x<a[j] do dec(j);
if not (i>j) then
begin
y:=a[i]; a[i]:=a[j]; a[j]:=y;
y:=b[i]; b[i]:=b[j]; b[j]:=y;
y:=c[i]; c[i]:=c[j]; c[j]:=y;
inc(i); dec(j);
end;
until i>j;
if i<r then sort(i,r);
if l<j then sort(l,j);
end;
function find(x:longint):longint;
var l,r,g,vt:longint;
begin
l:=1; r:=m*2; vt:=0;
while l<=r do
begin
g:=(l+r) div 2;
if a[g]>=x then
begin
vt:=g; r:=g-1;
end else l:=g+1;
end;
exit(vt);
end;
procedure Gao_Pink;
var i,u,v,l,r:longint; du,dv:int64;
begin
for i:=1 to n do d[i]:=high(int64);
l:=0; r:=1; d[s]:=0; q[r]:=s; p[r]:=0;
while l<r do
begin
inc(l); u:=q[l]; du:=p[l];
for i:=find(u) to m*2+2 do
if a[i]=u then
begin
v:=b[i]; dv:=c[i];
if d[v]>du+dv then
begin
d[v]:=du+dv; inc(r);
t[v]:=u; q[r]:=v; p[r]:=d[v];
end;
end else break;
end;
end;
procedure query;
var i,p:longint;
begin
writeln(d[f]); p:=0;
while f>0 do
begin
inc(p); kq[p]:=f; f:=t[f];
end;
for i:=p downto 1 do write(kq[i],' ');
end;
BEGIN
init; sort(1,m*2); Gao_Pink; query;
END.
Y29uc3QgTWF4TiA9IDEwMDAwMDE7CnZhciBuLG0scyxmOmxvbmdpbnQ7CiAgICBjLGQscSxwOmFycmF5WzAuLk1heE5dIG9mIGludDY0OwogICAgYSxiLHQsa3E6YXJyYXlbMC4uTWF4Tl0gb2YgbG9uZ2ludDsKcHJvY2VkdXJlIGluaXQ7CnZhciBpLHgseTpsb25naW50OyB6OmludDY0OwpiZWdpbgogICAgICAgIHJlYWQobixtLHMsZik7CiAgICAgICAgZm9yIGk6PTEgdG8gbSBkbwogICAgICAgIGJlZ2luCiAgICAgICAgICAgICAgICByZWFkKHgseSx6KTsKICAgICAgICAgICAgICAgIGFbaV06PXg7IGJbaV06PXk7IGNbaV06PXo7CiAgICAgICAgICAgICAgICBhW2krbV06PXk7IGJbaSttXTo9eDsgY1tpK21dOj16OwogICAgICAgIGVuZDsKZW5kOwpwcm9jZWR1cmUgc29ydChsLHI6bG9uZ2ludCk7CnZhciBpLGoseDpsb25naW50OyB5OmludDY0OwpiZWdpbgogICAgICAgIGk6PWw7IGo6PXI7IHg6PWFbKGkraikgZGl2IDJdOwogICAgICAgIHJlcGVhdAogICAgICAgICAgICAgICAgd2hpbGUgYVtpXTx4IGRvIGluYyhpKTsKICAgICAgICAgICAgICAgIHdoaWxlIHg8YVtqXSBkbyBkZWMoaik7CiAgICAgICAgICAgICAgICBpZiBub3QgKGk+aikgdGhlbgogICAgICAgICAgICAgICAgYmVnaW4KICAgICAgICAgICAgICAgICAgICAgICAgeTo9YVtpXTsgYVtpXTo9YVtqXTsgYVtqXTo9eTsKICAgICAgICAgICAgICAgICAgICAgICAgeTo9YltpXTsgYltpXTo9YltqXTsgYltqXTo9eTsKICAgICAgICAgICAgICAgICAgICAgICAgeTo9Y1tpXTsgY1tpXTo9Y1tqXTsgY1tqXTo9eTsKICAgICAgICAgICAgICAgICAgICAgICAgaW5jKGkpOyBkZWMoaik7CiAgICAgICAgICAgICAgICBlbmQ7CiAgICAgICAgdW50aWwgaT5qOwogICAgICAgIGlmIGk8ciB0aGVuIHNvcnQoaSxyKTsKICAgICAgICBpZiBsPGogdGhlbiBzb3J0KGwsaik7CmVuZDsKZnVuY3Rpb24gZmluZCh4OmxvbmdpbnQpOmxvbmdpbnQ7CnZhciBsLHIsZyx2dDpsb25naW50OwpiZWdpbgogICAgICAgIGw6PTE7IHI6PW0qMjsgdnQ6PTA7CiAgICAgICAgd2hpbGUgbDw9ciBkbwogICAgICAgIGJlZ2luCiAgICAgICAgICAgICAgICBnOj0obCtyKSBkaXYgMjsKICAgICAgICAgICAgICAgIGlmIGFbZ10+PXggdGhlbgogICAgICAgICAgICAgICAgYmVnaW4KICAgICAgICAgICAgICAgICAgICAgICAgdnQ6PWc7IHI6PWctMTsKICAgICAgICAgICAgICAgIGVuZCBlbHNlIGw6PWcrMTsKICAgICAgICBlbmQ7CiAgICAgICAgZXhpdCh2dCk7CmVuZDsKcHJvY2VkdXJlIEdhb19QaW5rOwp2YXIgaSx1LHYsbCxyOmxvbmdpbnQ7IGR1LGR2OmludDY0OyAKYmVnaW4KICAgICAgICBmb3IgaTo9MSB0byBuIGRvIGRbaV06PWhpZ2goaW50NjQpOwogICAgICAgIGw6PTA7IHI6PTE7IGRbc106PTA7IHFbcl06PXM7IHBbcl06PTA7CiAgICAgICAgd2hpbGUgbDxyIGRvCiAgICAgICAgYmVnaW4KICAgICAgICAgICAgICAgIGluYyhsKTsgdTo9cVtsXTsgZHU6PXBbbF07CiAgICAgICAgICAgICAgICBmb3IgaTo9ZmluZCh1KSB0byBtKjIrMiBkbwogICAgICAgICAgICAgICAgaWYgYVtpXT11IHRoZW4KICAgICAgICAgICAgICAgIGJlZ2luCiAgICAgICAgICAgICAgICAgICAgICAgIHY6PWJbaV07IGR2Oj1jW2ldOwogICAgICAgICAgICAgICAgICAgICAgICBpZiBkW3ZdPmR1K2R2IHRoZW4KICAgICAgICAgICAgICAgICAgICAgICAgYmVnaW4KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkW3ZdOj1kdStkdjsgaW5jKHIpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRbdl06PXU7IHFbcl06PXY7IHBbcl06PWRbdl07CiAgICAgICAgICAgICAgICAgICAgICAgIGVuZDsKICAgICAgICAgICAgICAgIGVuZCBlbHNlIGJyZWFrOwogICAgICAgIGVuZDsKZW5kOwpwcm9jZWR1cmUgcXVlcnk7CnZhciBpLHA6bG9uZ2ludDsKYmVnaW4KICAgICAgICB3cml0ZWxuKGRbZl0pOyBwOj0wOwogICAgICAgIHdoaWxlIGY+MCBkbwogICAgICAgIGJlZ2luCiAgICAgICAgICAgICAgICBpbmMocCk7IGtxW3BdOj1mOyBmOj10W2ZdOwogICAgICAgIGVuZDsKICAgICAgICBmb3IgaTo9cCBkb3dudG8gMSBkbyB3cml0ZShrcVtpXSwnICcpOwplbmQ7CkJFR0lOCiAgICAgICAgaW5pdDsgc29ydCgxLG0qMik7IEdhb19QaW5rOyBxdWVyeTsKRU5ELg==