#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)1e18
struct DSU {
vector<int> v;
DSU(int n) : v(n + 1, -1) {
}
int find(int a) {
return v[a] < 0 ? a : v[a] = find(v[a]);
}
void unite(int a, int b) {
a = find(a);
b = find(b);
if (a == b) {
return;
}
if (v[a] > v[b]) {
swap(a, b);
}
v[a] += v[b];
v[b] = a;
}
};
template<typename T>
using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,M,A,B;
cin>>N>>M>>A>>B;
vector<vector<pair<int,int>>>g(N+1);
for(int i=0;i<M;i++){
int a,b,w;
cin>>a>>b>>w;
g[a].emplace_back(b,w);
g[b].emplace_back(a,w);
}
vector<int>c(N+1,INF);
min_priority_queue<pair<int,int>>pq;
c[B]=0;
pq.emplace(0,B);
while(!pq.empty()){
auto[d,i]=pq.top();
pq.pop();
if(d>c[i]){
continue;
}
for(auto[j,w]:g[i]){
if(c[i]+w<c[j]){
c[j]=c[i]+w;
pq.emplace(c[j],j);
}
}
}
vector<int>v(N+1);
DSU dsu(N+1);
auto dfs1=[&](auto self,int i)->void{
if(v[i]){
return;
}
v[i]=1;
for(auto[j,_]:g[i]){
if(c[j]==c[i]){
dsu.unite(i,j);
}
if(c[j]<=c[i]){
self(self,j);
}
}
};
dfs1(dfs1,A);
vector<set<int>>gg(N+1);
for(int i=1;i<=N;i++){
for(auto[j,_]:g[i]){
if(c[j]<=c[i]&&dsu.find(j)!=dsu.find(i)){
gg[dsu.find(i)].insert(dsu.find(j));
}
}
}
vector<int>w(N+1),u(N+1);
auto dfs2=[&](auto self,int i)->void{
if(w[i]){
return;
}
int x=0;
for(int j:gg[i]){
self(self,j);
if(w[j]>x){
x=w[j];
u[i]=j;
}
}
w[i]=-dsu.v[dsu.find(i)]+x;
};
dfs2(dfs2,dsu.find(A));
vector<int>y(N+1);
for(int i=dsu.find(A);i;i=u[i]){
y[i]=1;
}
cout<<w[dsu.find(A)]<<'\n';
for(int i=1;i<=N;i++){
if(y[dsu.find(i)]){
cout<<i<<' ';
}
}
cout<<'\n';
return 0;
}