#include <iostream>
#include <vector>
#include <queue>
#include <climits>
#include <algorithm>
using namespace std;
const int INF = INT_MAX;
struct Edge {
int to;
int len;
};
void dijkstra(vector<vector<Edge>>& graph, vector<int>& dist, vector<int>& prev, int start) {
int n = graph.size();
dist[start] = 0;
prev[start] = -1;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
pq.push({0, start});
while (!pq.empty()) {
int u = pq.top().second;
pq.pop();
for (const auto& edge : graph[u]) {
int v = edge.to;
int len = edge.len;
if (dist[u] + len < dist[v]) {
dist[v] = dist[u] + len;
prev[v] = u;
pq.push({dist[v], v});
}
}
}
}
vector<int> getShortestPath(vector<int>& prev, int end) {
vector<int> path;
while (end != -1) {
path.push_back(end);
end = prev[end];
}
reverse(path.begin(), path.end());
return path;
}
int main() {
int n, m, s, t;
cin >> n >> m >> s >> t;
vector<vector<Edge>> graph(n + 1);
for (int i = 0; i < m; i++) {
int x, y, len;
cin >> x >> y >> len;
graph[x].push_back({y, len});
graph[y].push_back({x, len});
}
vector<int> dist(n + 1, INF);
vector<int> prev(n + 1, -1);
dijkstra(graph, dist, prev, s);
if (dist[t] == INF) {
cout << "can't arrive" << endl;
} else {
cout << dist[t] << endl;
vector<int> path = getShortestPath(prev, t);
for (int i = 0; i < path.size(); i++) {
cout << path[i] << " ";
}
cout << endl;
}
return 0;
}