#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 100'001;
vector<pair<int, ll>> g[MAXN];
vector<int> g2[MAXN];
int dp[MAXN], comp[MAXN], nxt[MAXN], n, m, a, b;
ll dist[MAXN];
void dijkstra(int source) {
fill(dist, dist+MAXN, 1e18);
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
dist[source] = 0;
pq.push({0, source});
while (!pq.empty()) {
auto [d, u] = pq.top(); pq.pop();
if (dist[u] != d) continue;
for (auto [v, w] : g[u]) {
if (dist[v] > dist[u] + w) {
dist[v] = dist[u] + w;
pq.push({dist[v], v});
}
}
}
}
void dfs(int u, int c) {
comp[u] = c;
for (auto [v, w] : g[u]) {
if (!comp[v] && dist[u] == dist[v]) dfs(v, c);
}
}
int timer = 1;
void build_graph() {
for (int i = 1; i <= n; i++) {
if (!comp[i]) dfs(i, timer++);
}
for (int i = 1; i <= n; i++) {
for (auto [u, w] : g[i]) {
if (dist[i] > dist[u]) g2[comp[i]].emplace_back(comp[u]);
}
}
for (int i = 1; i < timer; i++) {
sort(g2[i].begin(), g2[i].end());
g2[i].erase(unique(g2[i].begin(), g2[i].end()), g2[i].end());
}
}
int longest_route(int u) {
if (dp[u] == -1) {
dp[u] = INT_MIN;
for (int v : g2[u]) {
if (dp[u] < longest_route(v) + 1) {
nxt[u] = v;
dp[u] = dp[v] + 1;
}
}
}
return dp[u];
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
fill(dp, dp+MAXN, -1);
cin >> n >> m >> a >> b;
for (int i = 0; i < m; i++) {
int u, v; ll w; cin >> u >> v >> w;
g[u].emplace_back(v, w);
g[v].emplace_back(u, w);
}
dijkstra(b);
build_graph();
dp[comp[b]] = 0;
int u = comp[a];
vector<int> good = {comp[b]};
while (u != comp[b]) {
good.emplace_back(u);
u = nxt[u];
}
sort(good.begin(), good.end());
vector<int> ans;
for (int i = 1; i <= n; i++) {
if (binary_search(good.begin(), good.end(), comp[i])) ans.emplace_back(i);
}
cout << ans.size() << "\n";
for (int u : ans) cout << u << " ";
cout << "\n";
return 0;
}