#include "bits/stdc++.h" using namespace std; int main() { int N, M, S, G; cin >> N >> M >> S >> G; vector>> es(N); for (int i = 0; i < M; i++) { int a, b, c; cin >> a >> b >> c; es[a].push_back(make_pair(b, c)); es[b].push_back(make_pair(a, c)); } int MAX = 99999999; vector> dp(N); for (int i = 0; i < N; i++) { dp[i] = make_pair(MAX, -1); sort(es[i].begin(), es[i].end()); } dp[G] = make_pair(0, -1); priority_queue,int>> pq; pq.push(make_pair(make_pair(0, -1), G)); while (!pq.empty()){ auto now = pq.top(); pq.pop(); int p = now.second; if (dp[p] < now.first) continue; for (auto to : es[p]){ int p2 = to.first; auto next = make_pair(to.second + dp[p].first, p); if (dp[p2] > next){ dp[p2] = next; pq.push(make_pair(next, p2)); } } } string ans = to_string(S); while (S != G){ S = dp[S].second; ans += " " + to_string(S); } cout << ans << endl; }