#include using namespace std; int dist[201]; int backtracking[201]; vector > adj[201]; int main(void) { cin.tie(0); ios::sync_with_stdio(false); int N, M, S, G; int a, b, c; cin >> N >> M >> S >> G; for (int i = 0; i < M; i++) { cin >> a >> b >> c; adj[a].push_back(make_pair(b, c)); adj[b].push_back(make_pair(a, c)); } for (int i = 0; i < N; i++) { dist[i] = 1e9; } memset(backtracking, -1, sizeof(backtracking)); dist[S] = 0; priority_queue , vector>, greater>> pque; pque.push(make_pair(dist[S], S)); while (!pque.empty()) { int now = pque.top().second; pque.pop(); if (now == G) { break; } for (auto it : adj[now]) { int next = it.first; int cost = it.second; if (dist[next] > dist[now] + cost) { dist[next] = dist[now] + cost; backtracking[next] = now; pque.push(make_pair(dist[next], next)); } else if (dist[next] == dist[now] + cost) { //backtracking[next] = min(backtracking[next], now); if (backtracking[next] > now) { backtracking[next] = now; pque.push(make_pair(dist[next], next)); } } } } stack path; int now = G; path.push(now); while (1) { now = backtracking[now]; if (now == -1) { break; } path.push(now); } while (!path.empty()) { cout << path.top() << ' '; path.pop(); } cout << '\n'; return 0; }