#include #include #include #include #include #include #include #include using namespace std; template using pq = priority_queue, greater>; int main(){ long long N, M, A, B, C, S, G; long long from, alt, d; cin >> N >> M >> S >> G; pq> que; vector>> E(N); vector dist(N, 1e18), ans; vector visit(N); for (int i=0; i < M; i++){ cin >> A >> B >> C; E[A].push_back({B, C}); E[B].push_back({A, C}); } for (auto &x : E) sort(x.begin(), x.end()); dist[G] = 0; que.push({0, G}); while(!que.empty()){ tie(d, from) = que.top(); que.pop(); if (visit[from]) continue; visit[from] = 1; for (auto [to, C] : E[from]){ alt = d + C; if (alt < dist[to]){ dist[to] = alt; que.push({dist[to], to}); } } } ans.push_back(S); long long now = S; while(now != G){ for (auto [x, y] : E[now]){ if (dist[x] == dist[now] - y){ now = x; ans.push_back(now); } } } for (auto x : ans) cout << x << " "; cout << endl; return 0; }