#define _USE_MATH_DEFINES #include #include #include #include #include #include //#include #include #include #include #include #include #include ///////// #define REP(i, x, n) for(int i = x; i < n; i++) #define rep(i,n) REP(i,0,n) #define P(p) cout<<(p)< ///////// typedef long long LL; typedef long double LD; ///////// using namespace::std; ///////// const int Vmax = 200; int main(void){ std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::fixed;// //cout << setprecision(16);// int N,M,start,goal; cin>>N>>M>>start>>goal; int d[Vmax][Vmax]; int cost[Vmax][Vmax]; const int INF = (int)1e8/2; rep(i,Vmax)rep(j,Vmax){ d[i][j] = INF; cost[i][j] = INF; } rep(i,N){ d[i][i] = 0; cost[i][i] = 0; } int a,b,c; rep(i,M){ cin>>a>>b>>c; d[a][b] = c; d[b][a] = c; cost[a][b] = c; cost[b][a] = c; } rep(i,N)rep(j,N)rep(k,N){ d[j][k] = min( d[j][k],d[j][i]+d[i][k] ); } int now; now = start; vector ans; ans.push_back(now); bool flag=true; while(flag) { flag = false; rep(i,N){ if( now == i)continue; if( d[start][now]+cost[now][i]+d[i][goal] == d[start][goal] ){ now = i; flag = true; ans.push_back(now); break; } } } //ans.push_back(goal); vector::iterator it = ans.begin(); for(;it != ans.end();++it){ cout << *it; if( it+1 != ans.end() ){ cout << " "; }else{ cout << endl; } } return 0; }