#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define INF_MIN 100000000 #define INF 1145141919 #define INF_MAX 2147483647 #define LL_MAX 9223372036854775807 #define EPS 1e-10 #define PI acos(-1) #define LL long long using namespace std; #define MAX_N 201 #define MAX_M 40001 typedef pair P; //distance, next int N, M, S, G; int dp[MAX_N][MAX_N]; int dpOrigin[MAX_N][MAX_N]; int main(){ cin >> N >> M >> S >> G; for(int i = 0; i < N; i++){ for(int j = 0; j < N; j++){ dp[i][j] = dpOrigin[i][j] = INF_MIN; } dp[i][i] = dpOrigin[i][i] = 0; } for(int i = 0; i < M; i++){ int a, b, c; cin >> a >> b >> c; dpOrigin[a][b] = dpOrigin[b][a] = dp[a][b] = dp[b][a] = c; } for(int k = 0; k < N; k++){ for(int i = 0; i < N; i++){ for(int j = 0; j < N; j++){ dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]); } } } vector ans; int pos = S; while(true){ ans.push_back(pos); if(pos == G) break; for(int i = 0; i < N; i++){ if(pos == i) continue; if(dpOrigin[pos][i] + dp[i][G] == dp[pos][G]){ pos = i; break; } } } for(int i = 0; i < ans.size(); i++){ cout << ans[i]; if(i < ans.size() - 1) cout << " "; } cout << endl; return 0; }