#include #include #include #include #include #include #include #include #include #include #include #include #include #define repd(i,a,b) for (int i=(a);i<(b);i++) #define rep(i,n) repd(i,0,n) #define var auto #define mod 1000000007 #define inf 2147483647 typedef long long ll; using namespace std; int inputValue(){ int a; cin >> a; return a; } template void output(T a, int precision) { if(precision > 0){ cout << fixed << setprecision(precision) << a << "\n"; } else{ cout << a << "\n"; } } // end of template int main() { // source code int N = inputValue(); // station int M = inputValue(); // line int S = inputValue(); // start int G = inputValue(); // goal vector> E(N, vector(N, inf)); vector> C(N, vector(N, 0)); rep(i, N){ E[i][i] = 0; } rep(i, M){ int a, b, c; cin >> a >> b >> c; E[a][b] = c; E[b][a] = c; C[a][b] = c; C[b][a] = c; } rep(k, N){ rep(i, N){ rep(j, N){ E[i][j] = min(E[i][j], E[i][k] + E[k][j]); } } } cout << S; while (S != G) { rep(i, N){ if (C[S][i] && C[S][i] + E[i][G] == E[S][G]) { cout << " " << i; S = i; break; } } } output("", 0); return 0; }