#include using namespace std; const int INF = 1 << 30; typedef pair< int, int > Pi; struct edge { int to, cost; }; vector< edge > graph[10000]; int N, M, S, G; int main() { scanf("%d %d %d %d", &N, &M, &S, &G); while(M--) { int a, b, c; scanf("%d %d %d", &a, &b, &c); graph[a].push_back((edge){b, c}); graph[b].push_back((edge){a, c}); } priority_queue< Pi, vector< Pi >, greater< Pi > > que; que.emplace(0, G); vector< Pi > v(N, Pi(INF, INF)); v[G] = {0, -1}; while(!que.empty()) { auto p = que.top(); que.pop(); for(auto& e : graph[p.second]) { if(Pi(p.first + e.cost, p.second) >= v[e.to]) continue; v[e.to] = Pi(p.first + e.cost, p.second); que.emplace(v[e.to].first, e.to); } } vector< int > dd; int now = S; dd.push_back(S); while(now != G) { int net = 1 << 30; for(auto& k : graph[now]) { if(v[k.to].first + k.cost == v[now].first) net = min(net, k.to); } now = net; dd.push_back(now); } bool first = false; for(int i = 0; i < dd.size(); i++) { if(first++) putchar(' '); printf("%d", dd[i]); } putchar('\n'); }