#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 dist[Vmax]; fill_n(dist, Vmax, INF); bool use[Vmax]; fill_n(use, Vmax, false); priority_queue,greater> q; q.push( PII(0,goal) ); PII temp; while( !q.empty() ){ temp = q.top();q.pop(); if( use[temp.second] == true ) continue; use[temp.second] = true; dist[temp.second] = temp.first; for(int i=0;i ans; ans.push_back(now); bool flag=true; while(flag) { flag = false; rep(i,N){ if( now == i)continue; if( cost[now][i]+dist[i] == dist[now] ){ 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 << '\n'; } } return 0; }