#include #include #include #include #include #include const int max = 205; const int inf = 10000000; typedef std::pair P; P cost[max]; std::vector

g[max]; int n, s, gg; void dijkstra(int k){ std::priority_queue < P, std::vector

, std::greater

> que; for (int i = 0; i < n; ++i)cost[i].first = inf, cost[i].second = inf; cost[k].first = 0; que.push(P(0, k)); while (!que.empty()){ P p = que.top(); que.pop(); int v = p.second; if (cost[v].first < p.first)continue; for (int i = 0; i < g[v].size(); ++i){ P e = g[v][i]; if (cost[e.first].first == cost[v].first + e.second){ cost[e.first].second = std::min(cost[e.first].second, v); } if (cost[e.first].first > cost[v].first + e.second){ cost[e.first].first = cost[v].first + e.second; cost[e.first].second = v; que.push(P(cost[e.first].first, e.first)); } } } } int main(){ int m; std::cin >> n >> m >> s >> gg; for (int i = 0; i < m; ++i){ int a, b, c; std::cin >> a >> b >> c; P p(b, c), q(a, c); g[a].push_back(p); g[b].push_back(q); } dijkstra(gg); std::cout << s; while (cost[s].second != inf){ std::cout << " " << cost[s].second; s = cost[s].second; } std::cout << std::endl; return 0; }