n,m,s,t=gets.split.map &:to_i z=10**9 d=(1..n).map{[z]*n} e=(1..n).map{[z]*n} m.times{ u,v,c=gets.split.map &:to_i d[u][v]=d[v][u]=e[u][v]=e[v][u]=c } n.times{|w|n.times{|u|n.times{|v| d[u][u]=0 d[u][v]=[d[u][v],d[u][w]+d[w][v]].min }}} print u=s ( print' ',u=(0...n).find{|v| d[u][t]==e[u][v]+d[v][t] } )while u!=t