#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
struct edge {
int from, to, weight;
edge() : from(0), to(0), weight(0) {}
edge(int from_, int to_, int weight_) : from(from_), to(to_), weight(weight_) {}
};
const int maxn = 1e5;
const int inf = 1e16;
int n, m, start, last;
vector<edge> graph[maxn + 1];
vector<edge> edges;
int dist[maxn + 1];
bool done[maxn + 1];
void dijkstra() {
for(int i = 1; i <= n; i++) {
dist[i] = inf;
}
priority_queue<pair<int, int> > q;
q.push(mp(0, last));
dist[last] = 0;
while(!q.empty()) {
pair<int, int> p = q.top();
q.pop();
int cur_dist = -p.fi, cur = p.se;
if(done[p.se]) {
continue;
}
done[cur] = true;
for(edge nei : graph[cur]) {
if(cur_dist + nei.weight < dist[nei.to]) {
dist[nei.to] = cur_dist + nei.weight;
q.push(mp(-(cur_dist + nei.weight), nei.to));
}
}
}
}
int comp_cnt;
int comp[maxn + 1];
vector<int> by_comp[maxn + 1];
vector<int> graph_comps[maxn + 1];
int dp[maxn + 1];
int pre[maxn + 1];
void dfs(int cur) {
comp[cur] = comp_cnt;
by_comp[comp_cnt].pb(cur);
for(edge nei : graph[cur]) {
if((dist[nei.to] == dist[cur]) && !comp[nei.to]) {
dfs(nei.to);
}
}
}
bool better(int a, int b) {
return dist[by_comp[a][0]] < dist[by_comp[b][0]];
}
void solve() {
cin >> n >> m >> start >> last;
for(int i = 1; i <= m; i++) {
int a, b, c;
cin >> a >> b >> c;
edges.pb(edge(a, b, c));
graph[a].pb(edge(a, b, c));
graph[b].pb(edge(b, a, c));
}
dijkstra();
for(int i = 1; i <= n; i++) {
if(!comp[i]) {
comp_cnt++;
dfs(i);
}
}
for(edge e : edges) {
if(dist[e.from] < dist[e.to]) {
graph_comps[comp[e.to]].pb(comp[e.from]);
}
if(dist[e.from] > dist[e.to]) {
graph_comps[comp[e.from]].pb(comp[e.to]);
}
}
vector<int> comps(comp_cnt, 0);
for(int i = 0; i < comp_cnt; i++) {
comps[i] = i + 1;
}
sort(comps.begin(), comps.end(), better);
for(int cur : comps) {
for(int nei : graph_comps[cur]) {
if(dp[cur] < dp[nei]) {
dp[cur] = dp[nei];
pre[cur] = nei;
}
}
dp[cur] += (int) by_comp[cur].size();
}
cout << dp[comp[start]] << "\n";
/*for(int i = 1; i <= n; i++) {
cout << dist[i] << " ";
}
cout << "\n";
for(int i = 1; i <= comp_cnt; i++) {
cout << dp[i] << " " << pre[i] << " - ";
for(int x : by_comp[i]) {
cout << x << " ";
}
cout << "\n";
}*/
vector<int> ans_comps;
int tmp = comp[start];
ans_comps.pb(tmp);
while(tmp != comp[last]) {
tmp = pre[tmp];
ans_comps.pb(tmp);
}
vector<int> ans;
for(int x : ans_comps) {
for(int y : by_comp[x]) {
ans.pb(y);
}
}
sort(ans.begin(), ans.end());
for(int x : ans) {
cout << x << " ";
}
cout << "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}