#include using namespace std; #define rep(i,x) for(int i=0;i=0;--i) #define rrep1(i,x) for(int i=x;i>=1;--i) #define all(a) begin(a),end(a) #define fst first #define scd second #define PB push_back const int inf = 1e9; const int mod = 1e9 + 7; using pii=pair; using vpii=vector; struct edge{short to;int cost;}; vector G[1005]; int N, M, s, g; pair pre[1005]; int d[1005]; signed main() { cin >> N >> M >> s >> g; rep(i, M) { short a, b; int c; cin >> a >> b >> c; G[a].PB(edge{b, c}); G[b].PB(edge{a, c}); } rep(i, N) { pre[i] = pii(inf, N+4); } priority_queue> q; q.push(pii(0, g)); fill_n(d, N+1, inf); d[g] = 0; while (q.size()) { pii p = q.top(); q.pop(); short v = p.scd; int c = p.fst; if (d[v] < c) continue; for (edge &e : G[v]) { if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; q.push(pii(d[e.to], e.to)); } } } vector ans; short cur = s; ans.PB(s); while (cur != g) { short to = N+4; for (edge &e : G[cur]) { if (d[e.to] == d[cur] - e.cost) { to = min(to, e.to); } } ans.PB(to); cur = to; } rep(i, ans.size()) { if (i) cout << ' '; cout << ans[i]; } cout<