#include using namespace std; #define all(c) (c).begin(),(c).end() #define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--) #define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++) #define rep(i,n) REP(i,0,n) #define iter(c) __typeof((c).begin()) #define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++) #define pb(a) push_back(a) #define pr(a) cout<<(a)<> #define F first #define S second #define ll long long bool check(int n,int m,int x,int y){return (x<0||x>=n||y<0||y>=m)?false:true;} const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1}; typedef pair P; int main() { int n,m,s,g; cin >> n >> m >> s >> g; swap(s,g); vector

v[n]; rep(i,m) { int x,y,z; cin >> x >> y >> z; v[x].pb(P(y,z)); v[y].pb(P(x,z)); } rep(i,n) sort(all(v[i])); int d[n],p[n]; fill(d,d+n,MAX); priority_queue,greater

> que; p[s]=-1; d[s]=0; que.push(P(0,s)); while(!que.empty()) { P pp=que.top();que.pop(); int now=pp.S,cost=pp.F; if(now==g) break; rep(i,v[now].size()) { if(d[v[now][i].F]>d[now]+v[now][i].S) { d[v[now][i].F]=d[now]+v[now][i].S; p[v[now][i].F]=now; que.push(P(d[v[now][i].F],v[now][i].F)); } else if(d[v[now][i].F]==d[now]+v[now][i].S) p[v[now][i].F]=min(p[v[now][i].F],now); } } vector ans; while(g!=-1) { ans.pb(g); g=p[g]; } rep(i,ans.size()) { if(i) cout << " "; cout << ans[i]; } cout << endl; return 0; }