#include #define F first #define S second using namespace std; typedef struct { int to, cost; } Edge; typedef pair P; priority_queue

que; long long n, m, a, b, st, go, c, node[222]; vector G[222]; int main() { cin >> n >> m >> st >> go; // グラフ入力 for (int i = 0; i < m; i++) { cin >> a >> b >> c; G[a].push_back((Edge){b, c}); G[b].push_back((Edge){a, c}); } // node初期化 for (int i = 0; i < n; i++) { node[i] = 1 << 30; } // ダイク node[go] = 0; que.push(P(go, 0)); while (!que.empty()) { P p = que.top(); que.pop(); int v = p.F; if (node[v] < p.S) { continue; } for (int i = 0; i < G[v].size(); i++) { Edge e = G[v][i]; if (node[e.to] > node[v] + e.cost) { node[e.to] = node[v] + e.cost; que.push(P(e.to, node[e.to])); } } } // 経路復元 long long now = st, next; while (now != go) { next = 1 << 30; cout << now << ' '; for (int i = 0; i < G[now].size(); i++) { Edge e = G[now][i]; if (node[e.to] + e.cost == node[now]) { if (e.to < next) { next = e.to; } } } now = next; } cout << go << endl; }