#include #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; template struct edge{ int to; T wt; edge(int to,const T& wt):to(to),wt(wt){} }; template using weighted_graph=vector>>; template void add_undirected_edge(weighted_graph& G,int u,int v,const T& wt){ G[u].emplace_back(v,wt); G[v].emplace_back(u,wt); } template vector Dijkstra(const weighted_graph& G,int s){ constexpr T INF=numeric_limits::max(); int n=G.size(); vector d(n,INF); d[s]=0; priority_queue> Q; Q.emplace(0,s); while(!Q.empty()){ T d0=-Q.top().first; int u=Q.top().second; Q.pop(); if(d0>d[u]) continue; for(const auto& e:G[u]){ int v=e.to; if(d[v]>d[u]+e.wt) d[v]=d[u]+e.wt, Q.emplace(-d[v],v); } } return d; } int main(){ int n,m,s,t; scanf("%d%d%d%d",&n,&m,&s,&t); weighted_graph G(n); rep(i,m){ int u,v,c; scanf("%d%d%d",&u,&v,&c); add_undirected_edge(G,u,v,c); } auto d=Dijkstra(G,t); vector ans={s}; for(int u=s;u!=t;){ int next=n; for(auto e:G[u]) if(d[u]==d[e.to]+e.wt) next=min(next,e.to); u=next; ans.emplace_back(u); } rep(i,ans.size()) printf("%d%c",ans[i],i+1