#include #define rep(i, a) for (int i = 0; i < (a); i++) #define rep2(i, a, b) for (int i = (a); i < (b); i++) #define repr(i, a) for (int i = (a) - 1; i >= 0; i--) #define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--) using namespace std; typedef long long ll; const ll inf = 1e9; const ll mod = 1e9 + 7; struct edge { int to, cost; }; typedef pair P; vector G[200]; int dp[200]; ostream &operator <<(ostream &os, const vector &v) { rep (i, v.size()) { if (i) cout << " "; cout << v[i]; } return os; } int main() { int N, M, s, t; cin >> N >> M >> s >> t; rep (i, M) { int a, b, c; cin >> a >> b >> c; G[a].push_back((edge){b, c}); G[b].push_back((edge){a, c}); } priority_queue, greater

> q; q.emplace(0, t); rep (i, N) dp[i] = inf; dp[t] = 0; while (!q.empty()) { P p = q.top(); q.pop(); int v = p.second; for (edge e : G[v]) { if (dp[e.to] > dp[v] + e.cost) { dp[e.to] = dp[v] + e.cost; q.emplace(dp[e.to], e.to); } } } int curr = s; vector ans; ans.push_back(s); while (curr != t) { int minv = inf; for (edge e : G[curr]) { if (dp[curr] == dp[e.to] + e.cost) { minv = min(minv, e.to); } } curr = minv; ans.push_back(curr); } cout << ans << endl; return 0; }