#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) for (int i=0;i<(n);i++) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) #define inf 0x3f3f3f3f #define CLEAR(a) a = decltype(a)() #define MP make_pair #define ALL(a) (a).begin(),(a).end() #define pii pair #define pcc pair #define pic pair #define pci pair #define VS vector #define VI vector #define DEBUG(x) cout<<#x<<": "< G[MAX_V]; int d[MAX_V]; int pre[MAX_V]; void dijkstra(int s) { priority_queue, greater > que; memset(d, inf, sizeof(d)); d[s] = 0; que.push(pii(0, s)); while (not que.empty()) { pii p = que.top(); que.pop(); int v = p.second; if (d[v] < p.first) continue; for (auto &e : G[v]) { if (d[e.to] > d[v] + e.c) { d[e.to] = d[v] + e.c; pre[e.to] = v; que.push(pii(d[e.to], e.to)); } if (d[e.to] == d[v] + e.c) { if (v < pre[e.to]) pre[e.to] = v; } } } } vector get_path(int s, int t) { vector path; for (; t != s; t = pre[t]) path.push_back(t); return path; } int main(void) { int N, M, S, Goal; cin >> N >> M >> S >> Goal; REP(i, M) { int a, b, c; cin >> a >> b >> c; G[a].emplace_back(b, c); G[b].emplace_back(a, c); } for (auto &a : G) { sort(ALL(a), [](edge left, edge right) {return left.to < right.to; }); } dijkstra(Goal); vector v = get_path(Goal, S); for (auto &a : v) { cout << a << " "; } cout << Goal << endl; cout << endl; return 0; }