#include #include #include #include #include #include using namespace std; typedef long long int64; const int64 MAX_COST = (LLONG_MAX >> 6); struct Map1 { int id; int64 cost; bool operator<(const Map1& m) const { return cost > m.cost; } }; struct Map2 { int64 cost = MAX_COST; unordered_map prev; }; unordered_map> cost; Map2 root[200]; int n, m, s, g; int64 min_cost(int start, int end) { for(int i = 0; i < n; i++) root[i].cost = MAX_COST; priority_queue q; root[start].cost = 0; for(auto c : cost[start]) { Map1 m = {c.first, c.second}; root[c.first].prev[start] = true; root[c.first].cost = c.second; q.push(m); } while(!q.empty()) { int cur = q.top().id; q.pop(); for(auto c : cost[cur]) { int64 d = root[cur].cost + c.second; if(d < root[c.first].cost) { Map1 m = {c.first, d}; q.push(m); root[c.first].prev.clear(); root[c.first].prev[cur] = true; root[c.first].cost = d; } else if(d == root[c.first].cost) { //Map1 m = {c.first, d}; //q.push(m); root[c.first].prev[cur] = true; } } } return root[end].cost; } string enumerate(int i) { int size = root[i].prev.size(); if(size == 0) return to_string(i); string res = "a"; char c = '0' + i; for(auto p : root[i].prev) { string str = enumerate(p.first) + c; if(str < res) res = str; } return res; } int main(void) { cin >> n >> m >> s >> g; for(int i = 0; i < m; i++) { int a, b, c; cin >> a >> b >> c; cost[b][a] = cost[a][b] = c; } min_cost(s, g); string res = enumerate(g); for(int i = 0; i < res.size(); i++) if(i == 0) cout << res[i]; else cout << " " << res[i]; cout << endl; return 0; }