#include using namespace std; namespace { typedef double real; typedef long long ll; template ostream& operator<<(ostream& os, const vector& vs) { if (vs.empty()) return os << "[]"; os << vs[0]; for (int i = 1; i < vs.size(); i++) os << " " << vs[i]; return os; } template istream& operator>>(istream& is, vector& vs) { for (auto it = vs.begin(); it != vs.end(); it++) is >> *it; return is; } struct Edge { int from, to, cost; Edge(int from, int to, int cost) : from(from), to(to), cost(cost) {} }; int N, M, S, G; vector> Graph; void input() { cin >> N >> M >> S >> G; Graph.clear(); Graph.resize(N); for (int i = 0; i < M; i++) { int a, b, c; cin >> a >> b >> c; Graph[a].push_back(Edge(a, b, c)); Graph[b].push_back(Edge(b, a, c)); } } typedef pair> C; const int INF = 1<<28; const C INF_C = make_pair(INF, vector(1, 1000)); struct State { int v; C cost; State() {} State(int v, C cost) : v(v), cost(cost) {} }; bool operator<(const State& a, const State& b) { if (a.cost.first == b.cost.first) { a.cost.second > b.cost.second; } else { a.cost.first > b.cost.first; } } void solve() { priority_queue PQ; vector D(N, INF_C); D[S] = make_pair(0, vector(1, S)); PQ.push(State(S, D[S])); while (not PQ.empty()) { State s = PQ.top(); PQ.pop(); int v = s.v; int cost = s.cost.first; //cout << v << " " << cost << endl; vector& path = s.cost.second; for (int i = 0; i < Graph[v].size(); i++) { const Edge& e = Graph[v][i]; State nstate; nstate.v = e.to; path.push_back(e.to); nstate.cost = make_pair(cost + e.cost, path); path.pop_back(); if (D[nstate.v] > nstate.cost) { D[nstate.v] = nstate.cost; PQ.push(nstate); } } } cout << D[G].second << endl; } } int main() { input(); solve(); return 0; }