#include #define rep(i,a,b) for(int i=int(a);i st; bool dfs(int now, int res){ if(now == G && res == 0){ st.push(now); return true; } rep(i,0,N){ if(i == now || used[i] || res < dest[now][i])continue; used[i] = 1; if(dfs(i, res - dest[now][i])){ st.push(now); return true; } used[i] = 0; } return false; } main(){ cin >> N >> M >> S >> G; int dist[N][N]; rep(i,0,N)rep(j,0,N)dest[i][j] = dist[i][j] = INF; rep(i,0,N)dist[i][i] = 0; int A[M],B[M],C[M]; rep(i,0,M){ cin >> A[i] >> B[i] >> C[i]; dest[A[i]][B[i]] = dest[B[i]][A[i]] = C[i]; dist[A[i]][B[i]] = dist[B[i]][A[i]] = C[i]; } rep(i,0,N)rep(j,0,N)rep(k,0,N){ dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]); } //cout << dist[S][G] << endl; used[S] = 1; dfs(S, dist[S][G]); while(!st.empty()){ cout << st.top() << " "; st.pop(); } cout << endl; }