#include #define _overload(_1,_2,_3,name,...) name #define _rep(i,n) _range(i,0,n) #define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i) #define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__) #define _all(arg) begin(arg),end(arg) templatebool chmax(T &a, const T &b) { return (abool chmin(T &a, const T &b) { return (b; const int INF=1<<28; int S, G; int main() { int N, M; cin >> N >> M >> S >> G; vector edge(N, vi(N, INF)); vector dist; rep(i, M) { int a, b, c; cin >> a >> b >> c; edge[a][b] = edge[b][a] = c; } rep(i, N) { edge[i][i] = 0; } dist = edge; rep(k, N) rep(i, N) rep(j, N) { chmin(dist[i][j], dist[i][k] + dist[k][j]); } int cur = S; vector res; res.push_back(S); while (cur != G) { rep(i, N) { if (i == cur) continue; if(dist[S][cur] + edge[cur][i] + dist[i][G] == dist[S][G]) { cur = i; res.push_back(i); break; } } } rep(i, res.size()-1) { cout << res[i] << " "; } cout << res[res.size()-1] << endl; return 0; }