#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constexpr int inf = 1 << 28; //constexpr long long mod = 1000000007LL; //constexpr long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; void dijkstra(ll start, vector>>& graph, vector& dist) { dist[start] = 0; priority_queue, vector>, greater>> pq; vector used(dist.size(), false); pq.push(make_pair(0, start)); while (!pq.empty()) { ll d, node; tie(d, node) = pq.top(); pq.pop(); if (used[node]) continue; used[node] = true; for (pair element : graph[node]) { ll new_d, new_node; tie(new_node, new_d) = element; new_d += d; if (new_d < dist[new_node]) { dist[new_node] = new_d; pq.push(make_pair(dist[new_node], new_node)); } } } } int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ int n, m, st, go; scanf("%d %d %d %d", &n, &m, &st, &go); vector>> g(n); for (int i = 0; i < m; i++) { int a, b, c; scanf("%d %d %d", &a, &b, &c); g[a].emplace_back(b, c); g[b].emplace_back(a, c); } vector d(n, INF); dijkstra(go, g, d); queue q; q.push(st); vector res; while (!q.empty()) { int cur = q.front(); q.pop(); res.push_back(cur); if (cur == go) break; vector> vp; for (auto next : g[cur]) { vp.emplace_back(next.second + d[next.first], next.first); } sort(vp.begin(), vp.end()); q.push(vp[0].second); } for (int i = 0; i < res.size(); i++) { cout << res[i]; if (i + 1 == res.size()) cout << "\n"; else cout << " "; } return 0; }