#include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector VI; typedef vector VVI; #define ITER(c) __typeof__((c).begin()) #define FOREACH(it, c) for (ITER(c) it=(c).begin(); it != (c).end(); ++it) #define REP(i, n) for(int(i)=0;(i)<(n);++(i)) #define FOR(i, f, t) for(int(i)=(f);(i)<(t);(++i)) #define RREP(i, n) for(int(i)=(n)-1;(i)>=0;--(i)) #define mp make_pair #define pb push_back const int MOD = int(1e9+7); int N,M,S,G; int res = 0; template class Dijkstra { public: static const int inf = 1<<29; int m_num; vector > > m; void init(int n){ m_num = n; m.clear(); m.resize(n); } void add(int u, int v, _Tc e){ m[u].pb(mp(v,e)); } _Tc solve(int u, int v, vector > *pcost = NULL, vector *proute = NULL){ int n = m_num; vector > c(n, mp(inf,VI())); vector r(n, -1); priority_queue > q; c[u].first = 0; q.push(mp(0, u)); while(!q.empty()){ int u = q.top().second; q.pop(); FOREACH(it,m[u]){ int v = it->first; _Tc nc = c[u].first + it->second; VI ncr = c[u].second; ncr.push_back(v); if(c[v].first > nc || c[v].first == nc && c[v].second > ncr){ c[v] = make_pair(nc,ncr); r[v] = u; q.push(mp(-nc,v)); } } } if(pcost) *pcost = c; if(proute) *proute = r; return c[v].first; } }; int main(){ do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0); cin >> N >> M >> S >> G; Dijkstra d; d.init(N); REP(i,M){ int a,b,c; cin >> a >> b >> c; d.add(a,b,c); d.add(b,a,c); } VI route; d.solve(S, G, NULL, &route); VI rt; int i = G; while(i != S){ rt.pb(i); i = route[i]; } reverse(rt.begin(), rt.end()); int n = rt.size(); cout << S; REP(i,n) cout << " " << rt[i]; cout << endl; return 0; }