#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pr pair<int,int>

const ll MAXN = 100005;
const ll INF = 1e18;
vector <pair<int,int>> A[MAXN];
vector <bool> ktra(MAXN,false);
vector <ll> vet(MAXN,0),v;
priority_queue<pr,vector<pr>,greater<pr>> Q;
void dijkstra(int n,int xp, int dich){
    vector <ll> L(n+1,INF);
    L[xp]=0;
    Q.push({0,xp});
    while(!Q.empty()){
        auto canh=Q.top();
        ll u=canh.se;
        Q.pop();
        if(ktra[u]) continue;
        ktra[u]=true;
        for(auto x:A[u]){
            ll v=x.fi,w=x.se;
            if(L[v]>L[u]+w){
                L[v]=L[u]+w;
                vet[v]=u;
                Q.push({L[v],v});
            }
        }
    }

    ll ans=L[dich];
    if(L[dich]==INF){
        cout << 0 << "\n";
    }
    else{
        v.push_back(dich);
        while(dich!=xp){
            v.push_back(vet[dich]);
            dich=vet[dich];
        }
        cout << ans << "\n";
        for(ll i=v.size()-1 ; i>=0 ; i--) cout << v[i] << " ";
    }
}


int main(){
    ll n,m; cin >> n >> m;
    for(ll i=1 ; i<=m ; i++){
        ll u,v,x; cin >> u >> v >> x;
        A[u].push_back({v,x});
        A[v].push_back({u,x});
    }
    ll xp,dich;
    cin >> xp >> dich;
    dijkstra(n,xp,dich);
}
